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

Executes an indexed loop synchronously, 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 bool For<T>(
	T operation,
	int fromInclusive,
	int toExclusive,
	ParallelConfig? configuration,
	Action<int> body
)

Parameters

operation  T
The operation to be reported when Progress is set in configuration. Progress is reported only if this parameter is not .
fromInclusive  Int32
The start index, inclusive.
toExclusive  Int32
The end index, exclusive.
configuration  ParallelConfig
An optional configuration to adjust parallelization, cancellation or reporting progress.
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 and ThrowIfCanceled in configuration was set to .

Remarks

This method is similar to Parallel.For(int, int, ParallelOptions, Action<int>) but it can be used even in .NET Framework 3.5 and supports reporting progress.

If fromInclusive is greater than or equal to toExclusive, then the method returns without performing any iterations.

If operation is not , Progress is set in configuration 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.

  Note

This method blocks the caller until the iterations are completed. To perform the execution asynchronously use the BeginFor or ForAsync (in .NET Framework 4.0 and above) methods.

Exceptions

ArgumentNullExceptionbody is .
OperationCanceledExceptionThe operation has been canceled and ThrowIfCanceled in configuration was .

See Also