Class ResultTask<T>
A task that executes a callback and the provides a result. Only completion is reported, no intermediate progress.
Inherited Members
Namespace: NanoByte.Common.Tasks
Assembly: NanoByte.Common.dll
Syntax
public sealed class ResultTask<T> : TaskBase, IResultTask<T>, ITask
Type Parameters
Name | Description |
---|---|
T |
Constructors
ResultTask(String, Func<T>, Action)
A task that executes a callback and the provides a result. Only completion is reported, no intermediate progress.
Declaration
public ResultTask(string name, Func<T> work, Action cancellationCallback = null)
Parameters
Type | Name | Description |
---|---|---|
String | name | A name describing the task in human-readable form. |
Func<T> | work | The code to be executed by the task that provides a result. May throw WebException, IOException or OperationCanceledException. |
Action | cancellationCallback | An optional callback to be called when cancellation is requested via a CancellationToken. |
Properties
CanCancel
Indicates whether this task can be canceled once it has been started.
Declaration
public override bool CanCancel { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
Name
A name describing the task in human-readable form.
Declaration
public override string Name { get; }
Property Value
Type | Description |
---|---|
String |
Overrides
Result
The result of the task.
Declaration
public T Result { get; }
Property Value
Type | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The task is not Complete. |
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 |
---|---|
OperationCanceledException | The operation was canceled. |
IOException | The task ended with IOError. |
WebException | The task ended with WebError. |