Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

C# How to get the Web Browser object to work if you want to use threads?

Hi all,

 

I want to use the C#.NET Web Browser Object. Currently each tab that is added to my browser (using the browser object) is running one at a time and runs single threaded).

 

I want to create a new thread every time it needs to add a tab. But what happens is some kind of weird error and it crashes.

 

Here is a screenshot of the error.

 

I've already stated what web is by calling it a new web browser (it's just off screen)

 

 

error.PNG

 

This has been quite an annoying issue. Once this is fixed I can apply a similar thing to my Navigation so that my navigation is thread based.

 

Utilize all those cores and threads like a good programmer :).

 

 

Thanks guys

 


Also if anyone wants my Visual Studio theme, there's a link to download it.

http://www.mediafire.com/download/c6pgx0j9jzam0e0/AluminiumTech+VS+Theme+1.2+.vssettings

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill

iPhone 8 Plus (Mid 2019 to present)

Samaritan XTX (Early 2021 Upgrade - AMD Ryzen 9 3900XT (12C/24T)  (2021) , MSI X370 Gaming Pro Carbon, Corsair 32GB Vengeance LPX DDR4-2666 (2020) ,  Asus ROG Strix RX Vega 56 , Corsair RM850i PSU, Noctua NH-D15 CPU Cooler (2021), Samsung 860 EVO 500GB SSD, Seagate BarraCuda 6TB HDD (2020) , NZXT S340 Elite, Corsair ML 120 Pro, Corsair ML120 x2 (2021)

Link to post
Share on other sites

You need to think very carefully about the threading model... Moreover you haven't specified whether you are using WPF or WinForms. In any event basically UI components are owned by the UI thread of which you have exactly one of in a normal .NET application. While you may create components on another thread you can't easily (or at all) pass them to the context of another thread.

 

All updates that you want to make to your UI components from another thread must be done via the UI Dispatcher class by passing a delegate to its Invoke or BeginInvoke procedures.

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites
Just now, Nuluvius said:

You need to think very carefully about the threading model... Moreover you haven't specified whether you are using WPF or WinForms. In any event basically UI components are owned by the UI thread of which you have exactly one of in a normal .NET application. While you may create components on another thread you can't easily (or at all) pass them to the context of another thread.

 

All updates that you want to make to your UI components from another thread must be done via the UI Dispatcher class by passing a delegate to its Invoke or BeginInvoke procedure.

WinForms. I know WinForms handles multithreading well except in my experience, the web browser component crashes when I use a form in it when enabling multi-threading.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill

iPhone 8 Plus (Mid 2019 to present)

Samaritan XTX (Early 2021 Upgrade - AMD Ryzen 9 3900XT (12C/24T)  (2021) , MSI X370 Gaming Pro Carbon, Corsair 32GB Vengeance LPX DDR4-2666 (2020) ,  Asus ROG Strix RX Vega 56 , Corsair RM850i PSU, Noctua NH-D15 CPU Cooler (2021), Samsung 860 EVO 500GB SSD, Seagate BarraCuda 6TB HDD (2020) , NZXT S340 Elite, Corsair ML 120 Pro, Corsair ML120 x2 (2021)

Link to post
Share on other sites
1 minute ago, AluminiumTech said:

WinForms. I know WinForms handles multithreading well except in my experience, the web browser component crashes when I use a form in it when enabling multi-threading.

Have you researched your exception? ThreadStateException.

 

Not to be rude about this but what you are attempting sounds to me like an absolute train wreak... I don't think that you clearly understand threading enough at this point and I would strongly suggest that you go and do some research. Specifically Managed ThreadingTask Parallel Library (TPL), async & await and Task-based Asynchronous Pattern (TAP).

 

I really don't know why you are wasting your time pissing around in old and deprecating technologies such as WinForms either... Switch to WPF & MVVM at least and follow the modern standard patterns and practices that I have listed. I would suggest that you could easily spend the rest of the day reading through those links before you should even touch another single line of code to do with threading.

 

Ultimately though the decision is of course yours and I have seen you on this forum numerous times before ignoring the advice you have been given... you'll only be back here crying when it all blows up in your face again.

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×