i want to call webBrowser.Navigate(string urlString) synchronously where webBrowser is windows forms control. I do this in such 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 message is never shoved. WHY this code doesn't work properly?
Not the best way, but you can use this...
while (this.webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
Thread.Sleep(100);
}
Rather use this to retrieve the page syncronously:
this.webBrowser.DocumentCompleted += WebBrowserDocumentCompleted;
this.webBrowser.Navigate("http://google.com");
private void WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
MessageBox.Show("Operation has completed !");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With