Wait for program to continue till webbrowser finish loading site
-
Hey. I am having a program where I am navigating a site, but the program continiues before the site is done loading, which means I get errors in the program. I have tried: wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler( delegate { //MyCode } ); But the program still contiunues, and then returns back to that function it is done loading, and that still gets me error. I also tried private void Navigate2(String address) { if (String.IsNullOrEmpty(address)) return; if (address.Equals("about:blank")) return; if (!address.StartsWith("http://") && !address.StartsWith("https://")) { address = "http://" + address; } try { webBrowser1.Navigate(new Uri(address)); } catch (System.UriFormatException) { return; } } But that aint waiting neither for the site to finish loading. Can anyone help me please :)
-
Hey. I am having a program where I am navigating a site, but the program continiues before the site is done loading, which means I get errors in the program. I have tried: wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler( delegate { //MyCode } ); But the program still contiunues, and then returns back to that function it is done loading, and that still gets me error. I also tried private void Navigate2(String address) { if (String.IsNullOrEmpty(address)) return; if (address.Equals("about:blank")) return; if (!address.StartsWith("http://") && !address.StartsWith("https://")) { address = "http://" + address; } try { webBrowser1.Navigate(new Uri(address)); } catch (System.UriFormatException) { return; } } But that aint waiting neither for the site to finish loading. Can anyone help me please :)
you may use
ProgressChanged
event, and check fore.CurrentProgress
ande.MaximumProgress
Calin -
you may use
ProgressChanged
event, and check fore.CurrentProgress
ande.MaximumProgress
CalinThx very much.. I used these functions you mentioned and then a global variable.. private void Navigate2(String address) { if (String.IsNullOrEmpty(address)) return; if (address.Equals("about:blank")) return; if (!address.StartsWith("http://") && !address.StartsWith("https://")) { address = "http://" + address; _loaded = false; webBrowser1.Navigate(address); webBrowser1.ProgressChanged += new WebBrowserProgressChangedEventHandler(webBrowser_ProgressChanged); while (_loaded == false) { Wait(100); } return; } } private void webBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) { siteLoading.Value = (int)e.CurrentProgress; if (e.CurrentProgress >= e.MaximumProgress) { Wait(200); _loaded = true; ; } }
-
Thx very much.. I used these functions you mentioned and then a global variable.. private void Navigate2(String address) { if (String.IsNullOrEmpty(address)) return; if (address.Equals("about:blank")) return; if (!address.StartsWith("http://") && !address.StartsWith("https://")) { address = "http://" + address; _loaded = false; webBrowser1.Navigate(address); webBrowser1.ProgressChanged += new WebBrowserProgressChangedEventHandler(webBrowser_ProgressChanged); while (_loaded == false) { Wait(100); } return; } } private void webBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) { siteLoading.Value = (int)e.CurrentProgress; if (e.CurrentProgress >= e.MaximumProgress) { Wait(200); _loaded = true; ; } }
Cool! Calin Tatar