469,291 Members | 1,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,291 developers. It's quick & easy.

Problem loading a WebBrowser in a separate thread

I'm trying to parse html that resides locally by using the HtmlDocument class
and unfortunately you can only get an instance of an HtmlDocument through the
WebBrowser control.

Some of the html files I want to parse are quite large so I want to get the
HtmlDocument in a separate thread. But for some reason, whenever I move the
code to navigate the WebBrowser to a separate thread the DocumentCompleted
event is never fired. When I step through I can see that some of it is
loading but not all. Here is some code:
-----------
....
//Start the thread
Thread worker = new Thread(new ParameterizedThreadStart(LoadHtml));
worker.SetApartmentState(ApartmentState.STA);
worker.Start(files);
....

private void LoadHtml(object obj)
{
foreach(FileInfo fileinfo in (FileInfo[])obj)
{
//Create a new chapter and add it to the list of chapters
HtmlParser parser = new HtmlParser(fileinfo);
m_listHtmlParsers.Add(parser);
}
}

public class HtmlParser
{
public HtmlParser(FileInfo fileinfo)
{
//Set up our WebBrowser Control, which will Parse the HtmlDocument
//that it contains once the DocumentCompleted Event is fired
m_wbHtmlParser.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(ParseHtml) ;
m_wbHtmlParser.Navigate(m_fiChapterFile.FullName);
}

private void ParseHtml(object sender,
ebBrowserDocumentCompletedEventArgs e)
{
//We never get here
}
}

------------------
If I take this out of the thread, the DocuementCompleted event get's fired
and everything works. I think what is happening is that the thread is being
exited before the document is completely loaded. But I'm not sure how to
make sure all the HtmlParsers have fired the DocumentCompleted event before
the thread ends.

Any help would be greatly appreciated.
Oct 13 '06 #1
0 1264

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by daniel.manges | last post: by
reply views Thread by Jaret Brower | last post: by
11 posts views Thread by Anil Gupte | last post: by
2 posts views Thread by Vadim Rapp | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.