Making the webbrowser control synchronous

Posted by andy gaskell on Apr 1st, 2006

Here’s a little trick if you need to make the WebBrowser control behave synchronously instead of having to hookup to the DocumentCompleted event. Attaching/unattaching from that event makes code pretty messy. Anyway, here’s my solution – it works :)

this.webBrowser.Navigate(url);

while (this.webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
     Application.DoEvents();
}

So simpo.

Technorati Tags: ,

4 Responses

  1. dlyle Says:

    There is some danger in using Application.DoEvents() in that if you open and close your application quickly, you might get rogue process instances if you view your task manager — especially with the Application.DoEvents() inside a while loop.

  2. Josh Says:

    thanks so much for that tip, very simple, yet very effective. Does exactly what I need too.

    You saved me a TON of time.

  3. Naveed Qadri Says:

    Thanks man !!!
    You are a life savor.

    NBQ -

  4. Alan Says:

    Thanks, this saved a lot of my time.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.