Kostek Kostecki
Kostek Kostecki

Reputation: 39

Multiple WebBrowsers in one program

My problem is that I cannot run multiple Webbrowsers the same time.

When I want to scrap data using webbrowser1 from site1 and scrap another data using webbrowser2 from site2, only the first webbrowser is doing the job.

I tried to run them in separate threads, but it didn't work, too. I heard something about STA ApartmentState before main, but it is present there and still nothing.

How I can make both webbrowsers work in the same time ?

Upvotes: 0

Views: 1392

Answers (2)

Tudor
Tudor

Reputation: 62439

Indeed, the WebBrowser is an ActiveX component that can only run in a single-threaded environment. A similar question was asked recently: Trouble with timers and threads

My suggestion is to use the WebClient class instead to fetch data from multiple locations at the same time.

Upvotes: 1

Shekhar_Pro
Shekhar_Pro

Reputation: 18420

If the website you are trying to scrap data from does not dynamically change HTML through JavaScript you can simply use HtmlAgilityPack for this. It is best in my view and easy to work with. This will solve your problem of multiple browsers as you can asynchronously scrap data from multiple websites using different instance of HtmlDocument in different thread.

Upvotes: 2

Related Questions