views:

29

answers:

1

Hi,

The event of document_complete fires more than once. Which isn't really that bad. But the url i'm navigating to, never gets completely loaded. It gets fired like 2/3 times.

This is my document_completed event:

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    if (e.Url.AbsolutePath != this.wbrowser.Url.AbsolutePath) 
        return;
    else
        string doctext = this.wbrowser.DocumentText;
}

What am i doing wrong?

+2  A: 

You will get one DocumentCompleted event per frame/iframe, that's why there are several. If you don't get the last one it's because some resource is still loading or hanging. It could be an image, a script file, or some iframe.

Your best solution is to add a timeout, and continue your program if you get the last DocumentCompleted event, or your timeout kicks in.

Mikael Svenson
How should that timer look like? I just tried a while loop which checks if a bool is true. i got this bool inside the document_completed event too. But it never gets true.
Yustme
Nevermind, i added an extra bool to check if we are navigating. It got very fast in that while loop without naviging to an url. Now it checks first if we are navigating. And that worked. Thanks!
Yustme