I am using VB.net to write a parallel based code. I use Parallel.For to generate pairs of 500 objects or in combination C(500,2) such as the following code; but I found that it didn't always generate all combinations which should be 124750 (shown from variable Counter). No other thread was runing when this code was run. I am using a Win-7 32 Bit desktop with Intel Core i5 CPU
[email protected], 3.33 GHz and RAM 2GB. What's wrong with the code and how to solve this problem? Thank You.
Dim Counter As Integer = 0
Parallel.For(0, 499, Sub(i)
For j As Integer = i + 1 To 499
Counter += 1
Console.Write(i & ":" & j)
Next
End Sub)
Console.Writeline("Iteration number: " & Counter)