WebBrowser.DocumentCompleted is raised more than once

I’m trying to write several utilities to query web sites, so I decided on using the WebBrowser.DocumentText property to get the page content.
As it turns out, unlike Microsoft’s documentation, the DocumentCompleted event is raised several times for most sites. It was triggered 8 times for this blog.
If this page is an example, the first load is enough regarding content, so I’m using the Interlocked class to perform the event’s code only the first time the event was triggered.

Update: Turns out there is a solution to the problem.

Category: Programming

2 Responses to “WebBrowser.DocumentCompleted is raised more than once”

  1. Anonymous

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
    MessageBox.Show(”" + e.Url);
    }
    e.Url contians the document completed you put the check of your destination URL like in your case
    if(e.Url == “http://dotmad.blogspot.com/2007/05/webbrowserdocumentcompleted-is-raised.html” )
    {
    }

  2. Adi

    Thanks for the tip, but I tested it (writing the URL to a listbox inside the event) and I got two hits in which the URL was identical.


Leave a Reply