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)
public: generic<typename TSource> static ParallelLoopResult ForEach( IEnumerable<TSource>^ source, Action<TSource>^ body )
The type of the data in the source.
- Type: System.Collections.Generic::IEnumerable<>
An enumerable data source.
- Type: System::Action<>
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 following example uses the method to count the number of vowels and non-whitespace characters in a text file. In this case, 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).
Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.