For Method (Int64, Int64, ParallelOptions, Action(Int64))

Task Parallel System.Threading

Executes a for loop 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 For ( _
	fromInclusive As Long, _
	toExclusive As Long, _
	parallelOptions As ParallelOptions, _
	body As Action(Of Long) _
) As ParallelLoopResult
C#
public static ParallelLoopResult For(
	long fromInclusive,
	long toExclusive,
	ParallelOptions parallelOptions,
	Action<long> body
)

Parameters

fromInclusive
Type: System..::.Int64
The start index, inclusive.
toExclusive
Type: System..::.Int64
The end index, exclusive.
parallelOptions
Type: System.Threading.Tasks..::.ParallelOptions
A ParallelOptions instance that configures the behavior of this operation.
body
Type: System..::.Action<(Of <(Int64>)>)
The delegate that is invoked once per iteration.

Return Value

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

Remarks

The body delegate is invoked once for each value in the iteration range: [fromInclusive, toExclusive). It is provided with the iteration count (an Int64) as a parameter.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionThe exception that is thrown when the body argument is null.
System..::.ArgumentNullExceptionThe exception that is thrown when the parallelOptions argument is null.
System..::.OperationCanceledExceptionThe exception that is thrown when the CancellationToken in the parallelOptions argument is set.
System..::.AggregateExceptionThe exception that is thrown to contain an exception thrown from one of the specified delegates.
System..::.ObjectDisposedExceptionThe exception that is thrown when the the CancellationTokenSource associated with the the CancellationToken in the parallelOptions has been disposed.

See Also