here is sample code for starting multiple task
Task.Factory.StartNew(() =>
{
//foreach (KeyValuePair entry in dicLis
Another solution:
After the completion of all the operation inside Parallel.For(...)
it return an onject of ParallelLoopResult
, Documentation:
For returns a System.Threading.Tasks.ParallelLoopResult object when all threads have completed. This return value is useful when you are stopping or breaking loop iteration manually, because the ParallelLoopResult stores information such as the last iteration that ran to completion. If one or more exceptions occur on one of the threads, a System.AggregateException will be thrown.
The ParallelLoopResult
class has a IsCompleted
property that is set to false when a Stop()
of Break()
method has been executed.
Example:
ParallelLoopResult result = Parallel.For(...);
if (result.IsCompleted)
{
//Start another task
}
Note that it advised to use it only when breaking or stoping the loop manually (otherwise just use WaitAll
, WhenAll
etc).