Jump to content

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

AlTech

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

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

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 comment
Share on other sites

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.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

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 comment
Share on other sites

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

×