I am using Webrowser control to go to a url and do a step and that is it. The issue i am facing is the control works fine for exactly 2 times and then it stops working and does not load the url any more than i realized if i close the application and ran again it again works twice and then same thing . I have tried like this approx 5+ times happens each time so this is strange behavior.
The control is inside a thread.
var th = new Thread(() =>
{
using (var br = new WebBrowser())
{
br.DocumentCompleted += browser_DocumentCompleted;
br.ScriptErrorsSuppressed = true;
br.ScrollBarsEnabled = true;
br.AllowNavigation = true;
br.Navigate(urltoRun);
Application.Run();
}
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
th.Join(60000);
th = null;
And browser_DocumentCompleted:
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!string.IsNullOrEmpty(htmlResult))
return;
// DO SOMETHING...
}
I had the same problem and I had an exception, so make sure that "common language runtime exceptions" is checked in Exception Settings ( ctrl + alt + e will open the window).
If the webbrowser control isn't that friendly, you can try using "Cefsharp" for winform.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.