WebBrowser.Navigate synchronously

I want to call webBrowser.Navigate (string urlString) synchronously, where webBrowser is window shape control. I do it this way

... private delegate void NavigateDelegate(string s); ... private void Function() { NavigateDelegate navigateDelegate = new NavigateDelegate(this.webBrowser1.Navigate); IAsyncResult asyncResult = navigateDelegate.BeginInvoke("http://google.com", null, null); while (!asyncResult.IsCompleted) { Thread.Sleep(10); } MessageBox.Show("Operation has completed !"); } 

but the message is never locked. Why is this code not working correctly?

+4
source share
2 answers

Rather, use this to get the page in sync:

 this.webBrowser.DocumentCompleted += WebBrowserDocumentCompleted; this.webBrowser.Navigate("http://google.com"); private void WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { MessageBox.Show("Operation has completed !"); } 
+4
source

Not the best way, but you can use this ...

 while (this.webBrowser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); Thread.Sleep(100); } 
+3
source

All Articles