Class ForEachTask<T>
A task that executes an action once for each element of a collection.
Implements
Inherited Members
Namespace: NanoByte.Common.Tasks
Assembly: NanoByte.Common.dll
Syntax
public sealed class ForEachTask<T> : TaskBase, ITask
Type Parameters
Name | Description |
---|---|
T |
Constructors
ForEachTask(String, IEnumerable<T>, Action<T>, Action<T>)
Creates a new task that executes an action once for each element of a collection.
Declaration
public ForEachTask(string name, IEnumerable<T> target, Action<T> action, Action<T> rollback = null)
Parameters
Type | Name | Description |
---|---|---|
String | name | A name describing the task in human-readable form. |
IEnumerable<T> | target | A list of objects to execute the action for. Cancellation is possible between any two elements. |
Action<T> | action | The action to be executed once per element in |
Action<T> | rollback | An optional action to try to undo changes made by |
Properties
Name
A name describing the task in human-readable form.
Declaration
public override string Name { get; }
Property Value
Type | Description |
---|---|
String |
Overrides
UnitsByte
true
if UnitsProcessed and UnitsTotal are measured in bytes;
false
if they are measured in generic units.
Declaration
protected override bool UnitsByte { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
Methods
Execute()
The actual code to be executed.
Declaration
protected override void Execute()
Overrides
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.
Exceptions
Type | Condition |
---|---|
System.OperationCanceledException | The operation was canceled. |
IOException | The task ended with IOError. |
WebException | The task ended with WebError. |