Hi, I am new to threading and wanted to see how I could implement into one of my windows apps. So I do something like that shown below (running the same sub mySub from different threads).
But, as soon as I start to do that, I realise that I've no idea what that it's actually going to do exactly and I'm sort of thinking 'how could that possibly work'. I'm thinking these threads are going to intefere with eachother and perhaps I should be starting three instances of the class with sub mySub instead of having three threads working on the same sub in the same class? I'm assuming all the variables would keep getting reset by the different threads so passing the parameters becomes pointless (i.e. you pass the parameter blnRateAll which is set to True for thread one, but then thread 2 starts up and sets it False for instance, and now thread 1 see's it at False instead of True?).
So, how exactly would you want to set something like this up? Three threads running the same subroutine? Also, I'm getting cross thread errors with SelectSheet which is another form. For instance, it can't set lstSelectSheet itself because of the cross thread error. I had previously found some code creating a delegate sub to invoke the label on that form no matter what thread called it which seemed to work ok, so I guess I would have to do something similar again?
Dim alParam As New ArrayList
Dim paramTS As New ParameterizedThreadStart(AddressOf mySub)
Dim t1 As Thread = Nothing
Dim t2 As Thread = Nothing
Dim t3 As Thread = Nothing
'Create parameter array for the thread
Dim d1 As New SelectSheet
d1.lblSelectSheet.Text = "Please put in file 1 name"
alParam.Add(True) 'for blnRateAll
alParam.Add(True) 'for blnFirstPass
alParam.Add(False) 'for blnSecondPass
alParam.Add(False) 'for blnFinalPass
t1 = New Thread(paramTS)
Dim d2 As New SelectSheet
d2.lblSelectSheet.Text = "Please put in file 2 name"
alParam(0) = d2.lstSelectSheet.SelectedItem.ToString()
alParam(2) = False : alParam(3) = True
t2 = New Thread(paramTS)
Dim d3 As New SelectSheet
d1.lblSelectSheet.Text = "Please put in file 3 name"
alParam(0) = d3.lstSelectSheet.SelectedItem.ToString()
alParam(3) = False : alParam(4) = True
t3 = New Thread(paramTS)