473,588 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DocumentComplet ed
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 ParameterizedTh readStart(LoadH tml));
worker.SetApart mentState(Apart mentState.STA);
worker.Start(fi les);
....

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

public class HtmlParser
{
public HtmlParser(File Info fileinfo)
{
//Set up our WebBrowser Control, which will Parse the HtmlDocument
//that it contains once the DocumentComplet ed Event is fired
m_wbHtmlParser. DocumentComplet ed +=
new WebBrowserDocum entCompletedEve ntHandler(Parse Html);
m_wbHtmlParser. Navigate(m_fiCh apterFile.FullN ame);
}

private void ParseHtml(objec t sender,
ebBrowserDocume ntCompletedEven tArgs e)
{
//We never get here
}
}

------------------
If I take this out of the thread, the DocuementComple ted 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 DocumentComplet ed event before
the thread ends.

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

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

Similar topics

1
5923
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
1811
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 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...
0
1573
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 HTML snippets contain <objecttags for ActiveX Control. ActiveX Control loads and works without issue. VB.NET App Architecture: SAME as above except for: The WebBrowser Control is initially seeded by loading HTML from local disk. All Other
0
1115
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 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...
0
2195
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 incurred a network hit per image file. i wanted to avoid the overhead of a separate network connection for each image file, so i bundled all the images into the JAR file. yet, somehow, the loading time for the applet is slower now! i'm totally...
11
2812
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
1935
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 ie.navigate "http://www.google.com" do while isnothing(ie.document)
4
2611
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 strange thing is that until the page is refreshed with Internet Explorer, the error keeps occurring. I realize no one can debug an application that I can't even provide details about (I didn't write nor do I have access to it) but what difference...
6
13703
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 InitializeComponents stating that the ActiveX-Control 8856f961-340a-11d0-a96b-00c04fd705a2 cannot be initiated because the current thread isn't a single-thread apartment. Is there way of using the webbrowser control in multi threaded applications in .Net...
0
7927
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7857
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8220
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8222
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5723
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2367
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.