WebBrowser Events in a Thread

Carl2007

New member
Joined
Dec 19, 2007
Messages
2
Programming Experience
10+
I am developing a Windows Forms Application in VB.NET 2.0 which uses the WebBrowser class.

If I place the WebBrowser control in a thread (which must be a STAThread, according to the WebBrowser documentation) the events, such as DocumentCompleted, don't fire after Navigation.

Does anyone have any info on this?

Many thanks in advance.
 
The Navigate method is asynchronous so you don't really need to create the browser control in a different thread. Instead you can create any number of browsers and attach to same DocumentCompleted event where you can spawn threads if needed to do the work when ready.

The reason why your attempt failed is probably because the thread ended and browser was garbage collected and that there was no opening in code for the event to be raised also. Instead of using the DC event you could have done this to wait in thread:
VB.NET:
' navigate
Do Until browser.ReadyState = WebBrowserReadyState.Complete
    Application.DoEvents()
Loop
' handle document here
 
Back
Top