Yustme
Yustme

Reputation: 6265

Webbrowser control document_completed fires more than once

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?

Upvotes: 0

Views: 331

Answers (1)

Mikael Svenson
Mikael Svenson

Reputation: 39695

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.

Upvotes: 2

Related Questions