I have a win forms application that contains a Web Browser control. I need to be able to add delay between operations on the web-browser due to the asynchronous nature of navigating.
The Document_Complete event is worthless as it does not take into account that a page may contain multiple AJAX requests. The event ofter fires many times.
UPDATE
The AJAX Requests are made when the page is loaded. So the page loads and content in some DIV is fetched via an HTTP request. So the the Document_Complete event is raises when the document first loads and then when each (AJAX) HTTP request returns. No Bueno.
UPDATE2
My application attempts to read HtmlElements from the Webbrowser.Document object. Because the code executes faster than the HTTP Requests return... the document object does not contain all of the html elements.
What I need is some way to delay the call of methods in the main thread. I have tried using a timer:
private void startTimer()
{
timer.Interval = 2000;
timer.Start();
while (!BrowserIsReady)
{
//Wait for timer
}
}
This locks up the thread and the tick event never fires. This loops never ends.
I want to run a series of methods like this:
Navagate("http://someurl.com");
//delay
ClickALink();
//delay
Navagate("Http://somewhere.com");
//delay
Can I solve this problem with a timer and the BackgroundWorker? Can someone suggest a possible solution?