How to pass multiple parameters in thread in VB

Viewed 107263

I'm looking to pass two or more parameters to a thread in VB 2008.

The following method (modified) works fine without parameters, and my status bar gets updated very cool-y. But I can't seem to make it work with one, two or more parameters.

This is the pseudo code of what I'm thinking should happen when the button is pressed:

Private Sub Btn_Click() 

Dim evaluator As New Thread(AddressOf Me.testthread(goodList, 1))
evaluator.Start()

Exit Sub

This is the testthread method:

Private Sub testthread(ByRef goodList As List(Of OneItem), ByVal coolvalue As Integer)

    StatusProgressBar.Maximum = 100000
    While (coolvalue < 100000)
        coolvalue = coolvalue + 1
        StatusProgressBar.Value = coolvalue
        lblPercent.Text = coolvalue & "%"
        Me.StatusProgressBar.Refresh()
    End While

End Sub
9 Answers

With VB 14, you can do the following with Tuples:

Shared Sub _runner(data as (goodList As List(Of OneItem), coolvalue As Integer))
    Console.WriteLine($"goodList: {data.goodList}")
    Console.WriteLine($"coolvalue: {data.coolvalue}")
    ' do stuff...
End Sub
Dim thr As New Thread(AddressOf _runner)
thr.Start((myGoodList, cval))
Related