Serial .NET Parallel For - Lock After Each

I have several Parallel.For operations in a row.

I am currently studying each Parallel.For the return value ParallelLoopResultand sleep for 20 milliseconds until the member IsCompletedis set to true.


Dim plr as ParallelLoopResult 

plr = Parallel.For(...)

while not plr.IsCompleted
  Thread.Sleep(20)
end while

plr = Parallel.For(...)

while not plr.IsCompleted
  Thread.Sleep(20)
end while

.
.
.

How can I add a kernel level block (i.e. WaitHandle) instead of a loop and Thread.Sleep? Is there a completion event that fires Parallel.For? Parallel. To provide such a mechanism?

+5
source share
2 answers

Parallel.Forwill execute all the code for which it was called. IsCompletedreturns only false, then the cycle was interrupted.

http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallelloopresult.aspx:

IsCompleted true, , . IsCompleted false, LowestBreakIteration null, Stop . IsCompleted false, LowestBreakIteration , Break .

+4

WaitHandle Parallel.For(), - ( ). , , Task Thread, . goint, , Parallel.For() ( ), .

+1

All Articles