public sealed class ParallelFor: ParallelLoop<int>
System.Threading.Parallel.ParallelLoop<int>
ParallelFor
System.Threading.Parallel
Parallel
A parallel loop over consecutive integers, starting at 0
[Note: ParallelFor provides basic parallelism over an index space known in advance. The index space is 0..(N-1) for some value of N. This is the common case in -for- loops, and one can easily derive more complex arithmetic sequences via linear transformation of the index variable.]
System.Threading.Parallel Namespace
ParallelFor Constructors
ParallelFor(int) Constructor
ParallelFor(int, int) Constructor
ParallelFor Methods
public ParallelFor(int count);
Constructs a ParallelFor that will iterate over the integers 0..count-1.
- count
- number of loop iterations
The loop starts executing when method System.Threading.Parallel.ParallelFor.BeginRun is called.
System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace
public ParallelFor(int count, int numThreads);
Constructs a ParallelFor that will iterate over the integers 0..count-1.
- count
- number of loop iterations
- numThreads
- maximum number of threads to use
Exception Type Condition ArgumentException The value for numThreads is negative
The loop starts executing when method System.Threading.Parallel.ParallelFor.BeginRun is called.If numThreads is 0, then up to System.Threading.Parallel.ParallelEnvironment.MaxThreads threads are used instead. The value of numThreads includes the thread that created the System.Threading.Parallel.ParallelFor<T>, hence using numThreads=1 forces sequential execution.
System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace
public override void BeginRun(Action<T> action);
Begin executing iterations.
- action
- The Delegate that processes each work item.
Exception Type Condition ArgumentNullException action is null
.
This method is not thread safe. It should be called only once for a given instance of a ParallelFor.[Note: Implementations, particularly on single-threaded hardware, are free to employ the calling thread to execute all loop iterations.]
System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace
public override void Cancel();
Cancel any iterations that have not yet started
This method is safe to call concurrently on the same instance.
System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace