What is the best way to pause the loop while the web browser is loading the page?

I need a pause cycle until the web browser page loads.

string[] lines = (string[]) Invoke((ReadLine)delegate { return logins.Lines; }); foreach (string line in lines) { //.. if (TryParseUserDetails(line, false, out data) { //... wb.Navigate(url.Next()); } } 

How to wait for a wb page to load before continuing?

I tried using the polling flags, setting the variable as true in the WebBrowserDocumentCompletedEventHandler callback function. and then:

 wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler( delegate(object sender2, WebBrowserDocumentCompletedEventArgs args) { done = true; }); 

// ..

  wb.Navigate(url.Next(); while (!done) { } done = false; 

I am looking for something like:

 wb.WaitForDone(); 

Any help is appreciated. Thanks in advance.

0
source share
2 answers

You can try using AutoResetEvent instead of a boolean. How:

Out of cycle:

 AutoResetEvent evt = new AutoResetEvent(false); 

Then the event handler:

 wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler( delegate(object sender2, WebBrowserDocumentCompletedEventArgs args) { evt.Set(); }); 

and then in the loop:

 evt.WaitOne(); 
+1
source

Why not just make the right material in the DocumentCompleted callback, as indicated here: SO Question ?

+1
source

All Articles