ForEach()

Parallel::ForEach(const SharedPtr<Collections::Generic::IEnumerable<TSource>>&, const SharedPtr<ParallelOptions>&, const Action<TSource>&) method

Executes a foreach operation on an IEnumerable in which iterations may run in parallel.

template<typename TSource> static ParallelLoopResult System::Threading::Tasks::Parallel::ForEach(const SharedPtr<Collections::Generic::IEnumerable<TSource>> &source, const SharedPtr<ParallelOptions> &parallelOptions, const Action<TSource> &body)

Template parameters

ParameterDescription
TSourceThe type of the data in the source.

Arguments

ParameterTypeDescription
sourceconst SharedPtr<Collections::Generic::IEnumerable<TSource>>&An enumerable data source.
parallelOptionsconst SharedPtr<ParallelOptions>&An object that configures the behavior of this operation.
bodyconst Action<TSource>&The delegate that is invoked once per iteration.

Return Value

A ParallelLoopResult structure that contains information on what portion of the loop completed.

Exceptions

ExceptionDescription
System.OperationCanceledExceptionif the CancellationToken in parallelOptions is set.

Remarks

This method partitions the source enumerable and executes the body delegate on multiple threads concurrently.

Parallel::ForEach(const SharedPtr<Collections::Generic::IEnumerable<TSource>>&, const Action<TSource>&) method

Executes a foreach operation on an IEnumerable in which iterations may run in parallel.

template<typename TSource> static ParallelLoopResult System::Threading::Tasks::Parallel::ForEach(const SharedPtr<Collections::Generic::IEnumerable<TSource>> &source, const Action<TSource> &body)

Template parameters

ParameterDescription
TSourceThe type of the data in the source.

Arguments

ParameterTypeDescription
sourceconst SharedPtr<Collections::Generic::IEnumerable<TSource>>&An enumerable data source.
bodyconst Action<TSource>&The delegate that is invoked once per iteration.

Return Value

A ParallelLoopResult structure that contains information on what portion of the loop completed.

Remarks

Uses default ParallelOptions with unlimited parallelism and no cancellation.

See Also