Web浏览器控件C#的问题

时间:2019-01-20 10:04:57

标签: c# winforms webbrowser-control

我正在使用Webrowser控件转到url并执行步骤,仅此而已。 我面临的问题是该控件可以正常运行2次,然后它停止工作,并且加载的URL不会超过我关闭该应用程序并再次运行时所意识到的,它再次可以运行两次,然后再进行相同的操作。 我已经尝试过每次大约发生5次以上,所以这是奇怪的行为。

控件在线程内。

 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;

和browser_DocumentCompleted:

    private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (!string.IsNullOrEmpty(htmlResult))
            return;
    // DO SOMETHING...
    }

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,但是有一个例外,因此请确保在“例外设置”( ctrl + alt + e 将打开窗口。

如果Web浏览器控件不那么友好,则可以尝试对Winform使用“ Cefsharp”。

相关问题