Results 1 to 2 of 2

Thread: [2008] Multithreading?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    12

    [2008] Multithreading?

    Okay, so here it goes. I want to make my code create a thread for each user/password in a designated list. My code is as follows:

    Code:
        Dim szTmpUser as String, szTmpPass as String
    
    ---
    
        Private Function Start() As Boolean
            Dim Threadx As Thread
            For i = 0 To (ListBox1.Items.Count - 1)
                ListBox1.SetSelected(i, True)
                ListBox2.SetSelected(i, True)
                szTmpUser = ListBox1.SelectedItem
                szTmpPass = ListBox2.SelectedItem
                Threadx = New Thread(AddressOf LoginUser)
                Threadx.Start()
            Next i
        End Function
    
    ---
    
        Private Sub LoginUser()
            Dim usr As String, pwd As String
            usr = szTmpUser
            pwd = szTmpPass
            MsgBox(usr & "-" & pwd)
        End Sub
    However, when I try to use it with 4 accounts loaded into the list, it MsgBox's the same thing four times rather than having each one with different info. Sorry if this explanation isn't clear and thanks for any advice.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Multithreading?

    You need to pass the correct parameters to your thread's function.

    You could probably do this by creating a new class with your LoginUser method in it and the username and password properties as well. Declare the object, assign the username and password, and then in your threading call, call that object's Loginuser method.

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