0

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?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Yustme
  • 6,125
  • 22
  • 75
  • 104

1 Answers1

2

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
  • 39,181
  • 7
  • 73
  • 79
  • 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 Aug 07 '10 at 18:29
  • 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 Aug 07 '10 at 18:34
  • hey can u share how u achieved the solution – Prachur Apr 19 '11 at 14:42