I have an array (i), and I want to do some math calculations based on the i value with a Parallel.For().
But the problem is, after running the Parallel.For(), the values on my array are still 0.
This happens when my for is from 0 to 0.
This is my code :
Dim a(10) As Double
Parallel.For(0, 0, Sub(i)
a(i) = i + 2
'There is some calculations based on instead of previous line!
'But anyway, the result will be on a(i).
End Sub)
MessageBox.Show(a(0)) 'This returns 0!
For i As Integer = 0 To 0
a(i) = i + 2
Next
MessageBox.Show(a(0)) 'But this returns 2!
What is the problem?
From Microsoft’s documentation
If fromInclusive is greater than or equal to toExclusive, then the method returns immediately without performing any iterations.
Therefore nothing will happen when you use
Parallel.For(0,0,etc).Try
Parallel.For(0,1)and see if you get a result.