我正在尝试实现简单的网页截屏程序。当我在 UI 线程上使用我的代码时,一切似乎都没有问题,但是当我从非 UI 线程调用方法时,我无法再触发 WebBrowserDocumentCompleted 事件。我也试过这个:
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.DocumentCompleted += WebBrowserDocumentCompleted;
wb.Visible = true;
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
{
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
new Action(delegate { }));
}
程序只是无限期地挂在while循环中。有任何想法吗?