Executes a for each operation on an IEnumerable<(Of <(TSource>)>)
in which iterations may run in parallel.
Namespace:
System.Threading.Tasks
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Shared Function ForEach(Of TSource, TLocal) ( _
source As IEnumerable(Of TSource), _
localInit As Func(Of TLocal), _
body As Func(Of TSource, ParallelLoopState, TLocal, TLocal), _
localFinally As Action(Of TLocal) _
) As ParallelLoopResult |
C# |
---|
public static ParallelLoopResult ForEach<TSource, TLocal>(
IEnumerable<TSource> source,
Func<TLocal> localInit,
Func<TSource, ParallelLoopState, TLocal, TLocal> body,
Action<TLocal> localFinally
)
|
Parameters
- source
- Type: System.Collections.Generic..::.IEnumerable<(Of <(TSource>)>)
An enumerable data source.
- localInit
- Type: System..::.Func<(Of <(TLocal>)>)
The function delegate that returns the initial state of the local data
for each thread.
- body
- Type: System..::.Func<(Of <(TSource, ParallelLoopState, TLocal, TLocal>)>)
The delegate that is invoked once per iteration.
- localFinally
- Type: System..::.Action<(Of <(TLocal>)>)
The delegate that performs a final action on the local state of each
thread.
Type Parameters
- TSource
- The type of the data in the source.
- TLocal
- The type of the thread-local data.
Return Value
A
ParallelLoopResult structure
that contains information on what portion of the loop completed.
Remarks
Exceptions
Exception | Condition |
---|
System..::.ArgumentNullException | The exception that is thrown when the source
argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the body
argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the
localInit argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the
localFinally argument is null. |
System..::.AggregateException | The exception that is thrown to contain an exception
thrown from one of the specified delegates. |
See Also