I have a webbrowser object.
It is doing a lot of work so very often I run into a problem where objects are not loaded yet, or new request was not yet complete, etc.
So for now I’m using something like this:
Thread.Sleep(n);
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
// do stuff here
But as already mentioned, I don’t like it. It is pretty unreliable. Plus the thread gets frozen.
I’m sure I’ve seen somewhere in internet something like DownloadCompleteHandler (not sure about the name), which was starting the process of downloading the page asynchronously, and after it is finished – I could call another handler to tell it what to do next.
But I can’t find it again.
Would be great if someone can help.
I think you’re looking for the DocumentCompleted event.
The Navigated event is called when the page has been navigated to and has started loading, the DocumentCompleted event is called when the page has finished loading.
Edit
In response to your comment on your question; you’re looking for the ProgressChanged event.
In fact it’d be easier if you just read through the WebBrowser documentation on MSDN. On this page there’s a section for ‘Events’, which lists all of them and what they are used for.