ParallelHelperBeginForT(T, Int32, Int32, AsyncConfig, ActionInt32) Method

Begins to execute 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 IAsyncResult BeginFor<T>(
	T operation,
	int fromInclusive,
	int toExclusive,
	AsyncConfig? 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  AsyncConfig
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

IAsyncResult
An IAsyncResult that represents the asynchronous operation, which could still be pending.

Remarks

In .NET Framework 4.0 and above you can use also the ForAsyncT(T, Int32, Int32, TaskConfig, ActionInt32) method.

To get the result or the exception that occurred during the operation you have to call the EndFor method.

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

See Also