ParallelHelperForT(IAsyncContext, T, Int32, Int32, ActionInt32) Method

Executes an indexed loop using a context that may belong to a higher level, possibly asynchronous operation.

Definition

Namespace: KGySoft.Threading
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static bool For<T>(
	IAsyncContext context,
	T operation,
	int fromInclusive,
	int toExclusive,
	Action<int> body
)

Parameters

context  IAsyncContext
An IAsyncContext instance that contains information for asynchronous processing about the current operation.
operation  T
The operation to be reported when Progress in context is not . Progress is reported only if this parameter is not .
fromInclusive  Int32
The start index, inclusive.
toExclusive  Int32
The end index, exclusive.
body  ActionInt32
The delegate that is invoked once per iteration.

Type Parameters

T
The type of the operation parameter.

Return Value

Boolean
, if the operation completed successfully.
, if the operation has been canceled.

Remarks

This method blocks the caller thread but if context belongs to an async top level method, then the execution may already run on a pool thread. Degree of parallelism, the ability of cancellation and reporting progress depend on how these were configured at the top level method. To reconfigure the degree of parallelism of an existing context, you can use the AsyncContextWrapper class.

  Tip

See the Examples section of the AsyncHelper class for details about how to create a context for possibly async top level methods.

Exceptions

See Also