我有一个窗体窗体,其中包含浏览器导航到以表格形式发送数据的站点。我想将该表上的数据传输到应用程序,该应用程序对数据进行一些计算,然后报告计算是否成功。如果计算成功,网页浏览器应请求更多数据并重复该过程。如果不是,代码应该停止。InvokeMethod不能在窗体上工作
下面显示的代码允许第一次将数据导入到表格时正常工作。但是,调用InvokeMethod时,表中的数据不会刷新(代码未显示表明表中的数据相同)。有解决方案吗?
private void cmdRun_Click(object sender, EventArgs e)
{
//set reference to button go get a new game
WebBrowser WB = webBrowser1;
HtmlElementCollection SudokuTable; HtmlDocument Doc;
//set reference to the button to refresh the table
HtmlElement goButton = this.webBrowser1.Document.All["VeryHardLevelStr"];
RunAgain:
Doc = WB.Document; //get a new copy of the info
//Get the second form, tranfer the data and process it
Form FormSolver = GetSolverForm(); //set reference to form
//set reference to datagrid to transfer data to
DataGridView dGV1 = GetDGVQ1(FormSolver);
//set reference to button that starts processing the data
Button StartButton = GetNamedButton(FormSolver, "cmdStart");
//set reference to checkbox to determine if the processing was ok
CheckBox CheckBxOK = GetNamedCheckBox(FormSolver, "ckSolutionOK");
//set a reference to the table with the values
SudokuTable = Doc.GetElementsByTagName("TABLE");
//transfer the values to a table on another form
TransferDataToSolvingForm(SudokuTable, dGV1);
//start code on second form to process the data
StartButton.PerformClick();
//if a solution has been found close the form and request more data
//if not solution found let code stop
if (CheckBxOK.Checked)
{
//user wants to close other form if successful uf CloseOnSuccess is true
Boolean CloseOnSuccess = this.ckCloseSolverOnSuccess.Checked;
if (CloseOnSuccess)
{
FormSolver.Close(); //since a solution was arrived at close the form
goButton.InvokeMember("click"); //Click the key on web browser to request more data
while (WB.IsBusy == true) //wait till it has retreived the data
{
System.Threading.Thread.Sleep(50);
}
}
goto RunAgain; //go back a reanalyze the new data
}
}
什么被定义为 “工作”?你想要提交表单吗?或者你想要按钮的onclick事件处理程序被执行? – 2009-11-18 17:26:21