I'm using a Timer
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()
only processes pending Windows message loop items so it run into an infinity loop because Applicadion.DoEvents()
doesn't raise any WebBrowser's events (but only Windows one as I mentioned) so ReadyState
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.