ParallelHelperForAsync(Int32, Int32, ActionInt32) Method

Executes an indexed loop asynchronously, in which iterations may run in parallel.

Definition

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

Parameters

fromInclusive  Int32
The start index, inclusive.
toExclusive  Int32
The end index, exclusive.
body  ActionInt32
The delegate that is invoked once per iteration.

Return Value

Task
A Task that represents the asynchronous operation, which could still be pending.

Remarks

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

The Task returned by this method has no result because if there was no exception, then the loop is guaranteed to be completed.

  Note

This method adjusts the degree of parallelization automatically and does not support cancellation or reporting progress. Use the ForAsyncT(T, Int32, Int32, TaskConfig, ActionInt32) overload to adjust parallelization, set up cancellation or to report progress.

Exceptions

See Also