Class ForEachTask<T>
A task that executes an action once for each element of a collection.
public sealed class ForEachTask<T> : TaskBase, ITask
Type Parameters
T
- Inheritance
-
objectMarshalByRefObjectForEachTask<T>
- Implements
- Inherited Members
- Extension Methods
Constructors
ForEachTask(string, IEnumerable<T>, Action<T>, Action<T>?)
Creates a new task that executes an action once for each element of a collection.
public ForEachTask(string name, IEnumerable<T> target, Action<T> action, Action<T>? rollback = null)
Parameters
name
stringA name describing the task in human-readable form.
target
IEnumerable<T>A list of objects to execute the action for. Cancellation is possible between any two elements.
action
Action<T>The action to be executed once per element in
target
.rollback
Action<T>An optional action to try to undo changes made by
action
in case one of the invocations failed or the task was cancelled. Called once for each element for whichaction
was called (even if it failed), in reverse order. Any exceptions thrown here are logged and then ignored.
Properties
Name
A name describing the task in human-readable form.
public override string Name { get; }
Property Value
- string
UnitsByte
true
if UnitsProcessed and UnitsTotal are measured in bytes;
false
if they are measured in generic units.
protected override bool UnitsByte { get; }
Property Value
- bool
Methods
Execute()
The actual code to be executed.
protected override void Execute()
Remarks
State is automatically set to Started before calling this method, to Complete after a successful exit and to an appropriate error state in case on an exception. You can set additional TaskStates during execution.