|
-
Jun 17th, 2008, 10:50 AM
#1
Thread Starter
Junior Member
[2005] Multiple Threading Help
I'm making a program that will sign people and preform automated things when logged in to a website. I have a list box of usernames and passwords. I know how to go through them and such but I am trying to make this multi threaded. I need to know if there is some way to create a specific number of threads for the number of items in the list box and if possible, have them numbered 0, 1, 2 etc.
vbnet Code:
For i As Integer = 0 To lbAccs.Items.Count - 1
Me.Main = New System.Threading.Thread(AddressOf TreeSub)
Me.Main.IsBackground = True
Me.Main.Start()
'if they stop the program before all threads have been created
If cmdStart.Text = "Start" Then
SetText(lbLog, Now & " : Program Stopped")
End If
Next
Any help would be great. Thanks.
-
Jun 17th, 2008, 11:02 AM
#2
Re: [2005] Multiple Threading Help
I don't know that there is the precise thing you are asking for, but there are some things that might help. If you just start the thread in a loop like that, then you certainly won't have any way to identify the thread later. However, if you were to create an array of threads, you could give each one a name. Of course, in that case, you might also look at the thread pool, and look at the ManagedThreadID property in particular. That would give you something like a unique id for each thread, but then you would have to decide what to do with it.
My usual boring signature: Nothing
 
-
Jun 17th, 2008, 11:15 AM
#3
Re: [2005] Multiple Threading Help
I think you'll better off using BackgroundWorkers like this:
vb.net Code:
Public Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click For i As Integer = 0 To lbAccs.Items.Count - 1 Step 1 If cmdStart.Text <> "Start" Then Exit For Else Dim bgr As New System.ComponentModel.BackgroundWorker() AddHandler bgr.DoWork, AddressOf bgr_DoWork bgr.RunWorkerAsync(i.ToString()) End If Next End Sub Private Sub bgr_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) System.Threading.Thread.CurrentThread.Name = DirectCast(e.Argument, String) SetText(lbLog, Now & " : Program Stopped") 'etc. End Sub
-
Jun 17th, 2008, 11:19 AM
#4
Re: [2005] Multiple Threading Help
I'd go with using the ThreadPool, as SH mentioned.
-
Jun 17th, 2008, 11:22 AM
#5
Thread Starter
Junior Member
Re: [2005] Multiple Threading Help
 Originally Posted by Shaggy Hiker
I don't know that there is the precise thing you are asking for, but there are some things that might help. If you just start the thread in a loop like that, then you certainly won't have any way to identify the thread later. However, if you were to create an array of threads, you could give each one a name. Of course, in that case, you might also look at the thread pool, and look at the ManagedThreadID property in particular. That would give you something like a unique id for each thread, but then you would have to decide what to do with it.
I'll look into this approach, although, I also need the array to have specific properties to each array. I need the array to have the proper username and password for each array.
On the other post. I wasn't sure how to properly add BGworkers without adding them directly to the form. I will also try that.
-
Jun 17th, 2008, 11:33 AM
#6
Re: [2005] Multiple Threading Help
I suggested the background workers because dealing with multiple threads has always been hell for me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|