C#: How to multithread with webbrowser?

Status
Not open for further replies.

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
My program will be visiting several sites (over 100) and posting to them. I was wondering if it was possible to multithread it, if so how?

Also if its not possible how can I incorporate a numericUpDown object and by putting up the number in it tell my program to create more instances of webbrowser then to do what I tell it to do? :eek:h:
 

TEBot

Member
member
Joined
Feb 24, 2011
Posts
124
Reaction score
21
Points
15
Location
Auckland, NZ
Website
www.traffic-exchange-bot.com
I don't think you can multi thread a WebBrowser because it's a Control and I believe all Controls must be created from the main thread.

I've never used the NumericUpDown Control so I can't help you on that one, sorry. But I wouldn't think it would be to difficult, maybe use one of the events on the NumericUpDown Control and when the event fires use a for loop to interate based on the number in the NumericUpDown Control, each time it iterates create a new WebBrowser.
 

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
What about:

Code:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
           if (numericUpDown1.Value ==1)
           {

               ///Create browser
               ///


           }
           else if (numericUpDown1.Value == 2)
           {

               /// Create webbrowser
           }

        }

What code can I use to create several instances of the webbrowser?
 

Patel

Veteran
veteran
old school
senior
member
Joined
Aug 12, 2010
Posts
1,593
Reaction score
489
Points
133
Location
Inside Tang
Website
itspatel.com
Just use a tabbedcontrol and add a tab and a browser for each number

For Each i As Int = 1 to numupdown.text

not sure if that code will work. (mainly cuz its vb). but its somewhere near that
 

TEBot

Member
member
Joined
Feb 24, 2011
Posts
124
Reaction score
21
Points
15
Location
Auckland, NZ
Website
www.traffic-exchange-bot.com
Just use a tabbedcontrol and add a tab and a browser for each number

For Each i As Int = 1 to numupdown.text

not sure if that code will work. (mainly cuz its vb). but its somewhere near that
Like Patel said, except instead of the For Each you'd do something like this:

int lastIndex = Convert.ToInt32(numupdown.Text);
for (int i = 0; i < lastIndex; i++)
 

kytro360

Member
Original poster
member
Joined
Sep 9, 2009
Posts
376
Reaction score
6
Points
75
How do I add tabs in my browser? I already added the Tab Control
 
C

Chicken

Guest
Multithreading = a new thread which doesn't rely on the main thing, which means that it won't freeze even if it is working hard. Now, as for more than one webbrowser, seriously?

That will cause memory problems as webbrowsers consume a lot of resources, better doing webrequests.
 

MeKirk

Registered
Joined
Jul 21, 2011
Posts
2
Reaction score
0
Points
0
It's true you can't create controls on other threads but that's because it's not thread safe. Ofcourse it's possible, just when creating a thread add this option:

Code:
Thread th = new Thread(Function);
CheckForIllegalCrossThreadCalls = false; // this bypasses it
th.Start();

However be carefull with non-safe-threading.
 

syanide

Registered
Joined
Sep 14, 2010
Posts
5
Reaction score
0
Points
0
you can multi thread a browser control.. you simply need to make sure the thread you create is defined as STA -> a single threaded apartment..
 
Status
Not open for further replies.