简体   繁体   English

WebBrowser在同一线程上运行

[英]WebBrowser run on same thread

I need to prevent WebBrowser.Navigate() run on the same thread because I need the process to be certain order. 我需要防止WebBrowser.Navigate()在同一线程上运行,因为我需要使流程确定顺序。

I came across Async/Await implementation of WebBrowser class for .NET which uses async/await implementation but I have to use .net 3.5 which doesn't support it. 我遇到了用于.NET的WebBrowser类的Async / Await实现,该类使用async / await实现,但是我必须使用不支持它的.net 3.5。

Anyone know of any alternative methods? 有人知道其他替代方法吗?

As far as I understand your requirements, you can use the WebBrowser component's DocumentCompleted event in the following way: 据我了解您的要求,您可以通过以下方式使用WebBrowser组件的DocumentCompleted事件:

webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Loaded);
webBrowser.Navigate(...);

...

void Loaded(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // do stuff that needs to be run after the page is loaded
}

I ended up setting a flag on the main form. 我最终在主窗体上设置了一个标志。 Then there is a thread.sleep until the flag is reset. 然后有一个thread.sleep直到标志被重置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM