Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ForEach(TSource) Method (IEnumerable(TSource), Action(TSource, ParallelLoopState))
Collapse the table of content
Expand the table of content

Parallel.ForEach(Of TSource) Method (IEnumerable(Of TSource), Action(Of TSource, ParallelLoopState))

.NET Framework 4.6 and 4.5

Executes a foreach (For Each in Visual Basic) operation on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.

Namespace:  System.Threading.Tasks
Assemblies:   mscorlib (in mscorlib.dll)
  System.Threading.Tasks.Parallel (in System.Threading.Tasks.Parallel.dll)

'Declaration
Public Shared Function ForEach(Of TSource) ( _
	source As IEnumerable(Of TSource), _
	body As Action(Of TSource, ParallelLoopState) _
) As ParallelLoopResult

Type Parameters

TSource

The type of the data in the source.

Parameters

source
Type: System.Collections.Generic.IEnumerable(Of TSource)

An enumerable data source.

body
Type: System.Action(Of TSource, ParallelLoopState)

The delegate that is invoked once per iteration.

Return Value

Type: System.Threading.Tasks.ParallelLoopResult
A structure that contains information about which portion of the loop completed.

ExceptionCondition
ArgumentNullException

The source argument is Nothing.

-or-

The body argument is Nothing.

AggregateException

The exception that contains all the individual exceptions thrown on all threads.

The body delegate is invoked once for each element in the source enumerable. It is provided with the following parameters: the current element, and a ParallelLoopState instance that may be used to break out of the loop prematurely.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft