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: C#, WebBrowser control
April 27th, 2006 at 1:26 pm
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.
March 15th, 2007 at 11:47 am
thanks so much for that tip, very simple, yet very effective. Does exactly what I need too.
You saved me a TON of time.
August 10th, 2008 at 1:11 pm
Thanks man !!!
You are a life savor.
NBQ -
August 26th, 2008 at 11:12 am
Thanks, this saved a lot of my time.