I have the following code
Dim x As Integer = 0
Dim evtReport(SomeMap.Keys.Count - 1) As ManualResetEvent
For Each DeviceIp As String In SomeMap.Keys
evtReport(x) = New ManualResetEvent(False)
Dim thdReport As New Thread(New ParameterizedThreadStart(Sub() Me.CollectReportsNew(DeviceDetailsMap(DeviceIp), evtReport(x))))
thdReport.Name = "Something"
thdReport.Start()
If (x < evtReport.Count - 1) Then
x = x + 1
End If
Next
Now what I am trying to do is set the ManualReset
event by index from inside the CollectReportsNew
method.
But, inside the CollectReportsNew
method, I see the same evtReport
element sent. That is because the last index of x is sent instead of each thread getting its own element.
I don't understand why this is happening.