Parallel.ForEach<'TSource> Method (IEnumerable<'TSource>, Action<'TSource>)
Executes a foreach (For Each in Visual Basic) operation on an IEnumerable in which iterations may run in parallel.
Assembly: mscorlib (in mscorlib.dll)
static member ForEach<'TSource> : source:IEnumerable<'TSource> * body:Action<'TSource> -> ParallelLoopResult
An enumerable data source.
The delegate that is invoked once per iteration.
Return ValueType: System.Threading.Tasks.ParallelLoopResult
A structure that contains information about which portion of the loop completed.
The type of the data in the source.
The body delegate is invoked once for each element in the source enumerable. It is provided with the current element as a parameter.
The following example uses the ParallelLoopResult value returned by the method is ignored. Note that, because operations can run in parallel, you must ensure that incrementing the counter variables is an atomic operation, and that multiple threads do not attempt to access the counter variables simultaneously. For this purpose, the example uses the lock statement (in C#) and the SyncLock statement (in Visual Basic).method to count the number of vowels and non-whitespace characters in a text file. In this case, the
Available since 8
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 8.1