I have a win forms application that contains a web browser control. I need to add a delay between operations in a web browser due to the asynchronous nature of navigation.
The Document_Complete event is useless since it does not take into account that a page can contain multiple AJAX requests. The event is triggered many times.
UPDATE
AJAX requests are executed when the page loads. Thus, page loading and content in any DIV are retrieved using an HTTP request. Thus, the Document_Complete event occurs when the document is loaded first, and then each HTTP request (AJAX) is returned. No Bueno.
UPDATE2
My application is trying to read HtmlElements from a Webbrowser.Document object. Because the code runs faster than the HTTP requests are returned ... the document object does not contain all the html elements.
I need some way to defer method calls in the main thread. I tried using a timer:
private void startTimer() { timer.Interval = 2000; timer.Start(); while (!BrowserIsReady) {
This blocks the thread, and the tick event never fires. These loops never end.
I want to run a number of such methods:
Navagate("http://someurl.com"); //delay ClickALink(); //delay Navagate("Http://somewhere.com"); //delay
Is it possible to solve this problem with a timer and BackgroundWorker? Can anyone suggest a possible solution?
source share