Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.61 KB | None | 0 0
  1. Dim loopCount As Integer = 500
  2. Dim regularSum = Enumerable.Range(0, loopCount).Select(Function(n) Clng(n)).Sum
  3.  
  4. regularSum.Dump("Correct value")
  5.  
  6. Dim results = Enumerable.Range(0, 10).Select(Function(d)
  7.                                                  Dim total As Long = 0
  8.                                                  Parallel.For(0, loopCount, New ParallelOptions() With {.MaxDegreeOfParallelism = 8},
  9.                                                  Sub(n)
  10.                                                     'this code is running in multiple tasks and not running in the same thread.  
  11.                                                      total += CLng(n)
  12.                                                  End Sub)
  13.                                                  Return total
  14.                                              End Function).ToList
  15.  
  16.  
  17. results.Dump("Bad way.  Don't do this ever")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement