473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1104

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
I am at my wits' end. I have the following code: WebBrowser1.Navigate ("c:\path\page.htm") Text1.Text = WebBrowser1.Document.Links.length Where the page.htm has the following HTML: <html>
0
by: daniel.manges | last post by:
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...
0
by: Mark | last post by:
I am converting a VB6/COM application to VB.NET and must remove all COM objects. VB6/COM App Architecture: Windows Form hosts WebBrowser which loads HTML snippets from local disk. Some of the...
0
by: Jaret Brower | last post by:
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...
0
by: speedcoder | last post by:
hi all, i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and...
11
by: Anil Gupte | last post by:
....and how do I insert one into my form? I used in VB 6.0 last, but cannot figure out where it is in .Net Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
2
by: Vadim Rapp | last post by:
Hello, I want to create a webbrowser object programmatically, navigate to a URL, and then analyze the document. I create the following code (simplified): Dim ie as new webbrowser...
18
by: Zytan | last post by:
I have multiple threads writing to WebBrowser (using a function that checks InvokedRequired, and if so, invokes itself on the WebBrowser thread) and they are getting deadlocked. They only...
4
by: David | last post by:
I'm using the AxSHDocVw.WebBrowser control to download data from a webpage at work (it's an internal page on my company's intranet). The page produces a runtime error after a while and the...
6
by: Leon | last post by:
Hi there, I am trying to use the WebBrowser Control in a form which is being started in an own thread by the main form of my application. Unfortunately I am always getting an error in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.