title: is there an Application.DoEvents() for WebBrowser?
body: <p>I'm using a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.timer(v=vs.110).aspx" rel="nofollow noreferrer"><code>Timer</code></a> to determine if a page loaded using AJAX is ready and return from function only when it is ready (page load including ajax stuff was loaded). I was trying the code like the below but I figured out <a href="https://stackoverflow.com/questions/6795086/problem-with-application-doevents-while-waiting-for-webbrowser-to-finish-loadi"><code>Application.DoEvents()</code></a> only processes pending Windows message loop items so it run into an infinity loop because <code>Applicadion.DoEvents()</code> doesn't raise any <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser(v=vs.110).aspx" rel="nofollow noreferrer">WebBrowser</a>'s events (but only Windows one as I mentioned) so <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.readystate(v=vs.110).aspx" rel="nofollow noreferrer"><code>ReadyState</code></a> can't be update and never change.</p>
  
  <p>My question is: Is there any way to force <code>WebBrowser's</code> events <code>Application.DoEvents()</code> does?</p>
  
  <pre><code>static bool done = false;
  int[] foo()
  {
    int[] data;
   timer1.Interval = 1000;
              timer1.Tick += new EventHandler(delegate(object o, EventArgs ea)
                  {
                      if (browser.ReadyState == WebBrowserReadyState.Complete)
                      {
                          timer1.Stop();
                          data = extract_data();
                          done = true;
                      }
                  });
              timer1.Start();
  
              while(!done) /* return from function only if timer1 isn't running anymore */
              {
                  Application.DoEvents();
                  Thread.Sleep(1000);
              }
  
              return data;
  }
  </code></pre>
  
  <p>I'm aware about <code>Application.DoEvents()</code> "issues" but I can't find any other way to do that. An different approach to solve that is very welcome too.</p>