public sealed class ParallelForEach<T>: ParallelLoop<T>
Object
ParallelLoop<T>
ParallelForEach<T>
System.Threading.Parallel
Parallel
A parallel loop over a collection containing types of T.
A ParallelForEach<T> iterates over an enumerable collection. Method System.Threading.Parallel.ParallelForEach<T>.BeginRun activates processing of the iterations, using a callback provided. The collection shall not change while the ParallelForEach<T> is active, otherwise the behavior is undefined. Inherited method System.Threading.Parallel.ParallelLoop<T>.EndRun blocks until all iterations are finished. Inherited method System.Threading.Parallel.ParallelLoop<T>.Run is shorthand for System.Threading.Parallel.ParallelForEach<T>.BeginRun and System.Threading.Parallel.ParallelLoop<T>.EndRun.[Note: ParallelForEach<T> is generally none-scalable in terms of parallelism, because the enumerator is inherently sequential. If the collection allows random access, consider using class System.Threading.Parallel.ParalleFor instead. ]
System.Threading.Parallel Namespace
ParallelForEach<T> Constructors
ParallelForEach<T>(System.IEnumerable<T>) Constructor
ParallelForEach<T>(System.IEnumerable<T>, int) Constructor
ParallelForEach<T> Methods
ParallelForEach<T>.BeginRun Method
ParallelForEach<T>.Cancel Method
public ParallelForEach(IEnumerable<T> collection);
Constructs a ParallelForEach<T> for iterating over a collection.
- collection
- collection of values over which to iterate
The loop does not start executing until at least method System.Threading.Parallel.ParallelForEach<T>.BeginRun is called and possibly not until method System.Threading.Parallel.ParallelLoop<T>.EndRun is called.
System.Threading.Parallel.ParallelForEach<T> Class, System.Threading.Parallel Namespace
public ParallelForEach(IEnumerable<T> collection, int numThreads);
Constructs a ParallelForEach<T> for iterating over a collection.
- collection
- collection of values over which to iterate
- numThreads
- maximum number of threads to use
Exception Type Condition ArgumentException The value for numThreads is negative
The loop does not start executing until at least method System.Threading.Parallel.ParallelForEach<T>.BeginRun is called and possibly not until method System.Threading.Parallel.ParallelLoop<T>.EndRun is called.If numThreads is 0, then up to System.Threading.Parallel.ParallelEnvironment.MaxThreads threads are used instead. The value includes the thread that created the System.Threading.Parallel.ParallelFor<T>, hence using numThreads=1 causes sequential execution.
System.Threading.Parallel.ParallelForEach<T> 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 ParallelWhile<T>.[Note: Implementations, particularly on single-threaded hardware, are free to employ the calling thread to execute all loop iterations.]
System.Threading.Parallel.ParallelForEach<T> 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.Does not cancel any future iterations that might be added.
System.Threading.Parallel.ParallelForEach<T> Class, System.Threading.Parallel Namespace