I'm using a [`Timer`](http://msdn.microsoft.com/en-us/library/system.windows.forms.timer(v=vs.110).aspx) 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 [`Application.DoEvents()`](https://stackoverflow.com/questions/6795086/problem-with-application-doevents-while-waiting-for-webbrowser-to-finish-loadi) only processes pending Windows message loop items so it run into an infinity loop because `Applicadion.DoEvents()` doesn't raise any [WebBrowser](http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser(v=vs.110).aspx)'s events (but only Windows one as I mentioned) so [`ReadyState`](http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.readystate(v=vs.110).aspx) can't be update and never change.

My question is: Is there any way to force `WebBrowser's` events `Application.DoEvents()` does?

```
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;
}

```

I'm aware about `Application.DoEvents()` "issues" but I can't find any other way to do that. An different approach to solve that is very welcome too.