0

I need pause loop until that the webbrowser complete page load.

 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 the wb page load to before continue loop?

I tried using polling-flags, setting an variable as true in 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'm looking for something like:

wb.WaitForDone(); 

Any help is appreciated. Thanks in advance.

The Mask
  • 17,007
  • 37
  • 111
  • 185

2 Answers2

1

Why not simply do the stuff you want within the DocumentCompleted Callback like stated here: SO Question?

Community
  • 1
  • 1
dasheddot
  • 2,936
  • 4
  • 26
  • 33
1

You can try to use an AutoResetEvent instead of the boolean. Like:

Outside the loop:

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();
Tudor
  • 61,523
  • 12
  • 102
  • 142
  • 1
    You might wanna replace that EventHandler with something like: `wb.DocumentCompleted += (o, args) => evt.Set();` - just to make it readable. – ebb Nov 24 '11 at 14:12