ParallelHelperForAsyncT(T, Int32, Int32, TaskConfig, ActionInt32) Method

Executes an indexed loop asynchronously, in which iterations may run in parallel and the execution can be configured.

Definition

Namespace: KGySoft.Threading
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static Task<bool> ForAsync<T>(
	T operation,
	int fromInclusive,
	int toExclusive,
	TaskConfig? asyncConfig,
	Action<int> body
)

Parameters

operation  T
The operation to be reported when Progress is set in asyncConfig. Progress is reported only if this parameter is not .
fromInclusive  Int32
The start index, inclusive.
toExclusive  Int32
The end index, exclusive.
asyncConfig  TaskConfig
An optional configuration to adjust parallelization, cancellation, completion callback or reporting progress.
body  ActionInt32
The delegate that is invoked once per iteration.

Type Parameters

T
The type of the operation parameter.

Return Value

TaskBoolean
A task that represents the asynchronous operation. Its result is , if the operation completed successfully, or , if the operation has been canceled and ThrowIfCanceled in asyncConfig parameter was .

Remarks

If fromInclusive is greater than or equal to toExclusive, then the operation completes synchronously without performing any iterations.

If operation is not , Progress is set in asyncConfig and there is at least one iteration, then the IAsyncProgress.New method will be called before the first iteration passing the specified operation to the operationType parameter. It will be followed by as many IAsyncProgress.Increment calls as many iterations were completed successfully.

This method is not a blocking call even if the MaxDegreeOfParallelism property of the asyncConfig parameter is 1.

Exceptions

ArgumentNullExceptionbody is .
TaskCanceledExceptionThe operation has been canceled and ThrowIfCanceled in asyncConfig was . This exception is thrown when the result is awaited.

See Also