简体   繁体   中英

Firing WebBrowser.DocumentCompleted event whilst in a loop

I have a simple app I am developing that needs to iterate through a list of URLs which are passed to a WebBrowsers Navigate function in a for each loop. I was hoping to see the DocumentCompleted event firing after each call of the Navigate function but it only seems to be fired after the whole form has completed loading - and this the loop has completed.

I guess I am missing something fundamental here but some help and advice would be great!

Thanks!

Here is a sample of code that I am trying...

This foreach loop runs n the Form Load event of the WinForms page I am using...

            int id = 0;
        foreach (DataRow row in quals.Rows)
        {
            URN = row["LAIM_REF"].ToString();

            string URN_formated = URN.Replace("/", "_");
            string URL = "http://URL_I_AM_GOING_TOO/";
            string FullURL = URL + URN_formated;

            wbrBrowser.ScriptErrorsSuppressed = true;
            wbrBrowser.Refresh();
            wbrBrowser.Navigate(FullURL);

            id += 1;

            label1.Text = id.ToString();

        }

At the point the loop gets to the line:

wbrBrowser.Navigate(FullURL);

I was hoping that the event:

        private void wbrBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
...
}

would fire therefore being able to run processes against each of the URLs returned in the loop.

Thanks!

I used:

while (wbrBackground.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }

after the Navigate function and it now works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM