简体   繁体   中英

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.

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.

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 += 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.

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.

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