Results 1 to 6 of 6

Thread: [2005] Multiple Threading Help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    19

    [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:
    1. For i As Integer = 0 To lbAccs.Items.Count - 1
    2.         Me.Main = New System.Threading.Thread(AddressOf TreeSub)
    3.         Me.Main.IsBackground = True
    4.         Me.Main.Start()
    5.         'if they stop the program before all threads have been created
    6.             If cmdStart.Text = "Start" Then
    7.                 SetText(lbLog, Now & " : Program Stopped")
    8.             End If
    9.         Next

    Any help would be great. Thanks.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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

  3. #3
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: [2005] Multiple Threading Help

    I think you'll better off using BackgroundWorkers like this:

    vb.net Code:
    1. Public Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
    2.     For i As Integer = 0 To lbAccs.Items.Count - 1 Step 1
    3.         If cmdStart.Text <> "Start" Then
    4.             Exit For
    5.         Else
    6.             Dim bgr As New System.ComponentModel.BackgroundWorker()
    7.             AddHandler bgr.DoWork, AddressOf bgr_DoWork
    8.             bgr.RunWorkerAsync(i.ToString())
    9.         End If
    10.     Next
    11. End Sub
    12.  
    13. Private Sub bgr_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
    14.     System.Threading.Thread.CurrentThread.Name = DirectCast(e.Argument, String)
    15.     SetText(lbLog, Now & " : Program Stopped")
    16.     'etc.
    17. End Sub

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Multiple Threading Help

    I'd go with using the ThreadPool, as SH mentioned.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    19

    Re: [2005] Multiple Threading Help

    Quote 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.

  6. #6
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    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
  •  



Click Here to Expand Forum to Full Width