I need to use a Windows.Forms.WebBrowser in a separate thread. (I'm
not using the GUI, I just want to navigate to a page and get the
..Document.Body.InnerText property of the WebBrowser - maybe there is
another way to do this?).
To make the instance, I set the thread to run in STA mode.
However, the DocumentCompleted event never gets called. It works fine
if I don't using threading, but in multi-threading, the event for
DocumentCompleted never happens.
//--------------
private void button2_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(DoIt));
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private void DoIt()
{
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(wb_Documen tCompleted);
wb.Navigate("http://www.google.com");
}
private void wb_DocumentCompleted(object sender, EventArgs e)
{
//THE CODE NEVER GETS HERE
string text = ((WebBrowser)sender).Document.Body.InnerText;
this.strTest = text;
}