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.
June 29th, 2010 at 1:52 pm
That solution will leave your CPU humming and eating up resources like mad.
I add a System.Threading.Thread.Sleep(50); to help but even that doesn’t help much.
I really wish I could come up with a good solution for this.
I NEED to be able to make it synchronous.
November 5th, 2010 at 9:41 am
The thread.sleep does nothing but delay the entire thread – essentially holding everything up.
I am happy with the DoEvents solution.
December 1st, 2010 at 1:43 am
But what happen when ready state in readyState_InteractiveClick
It is happen when filedownload box display and click on cancel button then ready state is readySate_InteractiveClick
How to get back in readyState_Completed
Please Help Me
Thanks In advaced
VJ