English 中文(简体)
InvokeMethod not working on windows form
原标题:
  • 时间:2009-11-16 21:27:49
  •  标签:
  • .net
  • browser

I have a windows form containing a webbrowser that navigates to a site which sends data back in the form of a table. I would like to transfer the data on that table to a application that runs some calculations on the data and then reports whether the calculations were successful or not. If the calculations were sucessful the webbrowser should request more data and repeat the process. If not the code should stop.

The code shown below allows works correctly the first time data is imported to the table. However, when the InvokeMethod is called the data in the table is not refreshed (code not shown indicates that the data in the table is the same). Is there a solution?

   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
        }
    }
问题回答

If I understand you correctly, you show the table data in the browser, and this is not being updated after the first time it is loaded. If this is the case, make sure WebBrowser.AllowNavigation is set to true:

Gets or sets a value indicating whether the control can navigate to another page after its initial page has been loaded.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签