Table of Contents

Class ResultTask<T>

Namespace
NanoByte.Common.Tasks
Assembly
NanoByte.Common.dll

A task that executes a callback and the provides a result. Only completion is reported, no intermediate progress.

public sealed class ResultTask<T> : TaskBase, IResultTask<T>, ITask

Type Parameters

T
Inheritance
object
MarshalByRefObject
ResultTask<T>
Implements
Inherited Members
Extension Methods

Constructors

ResultTask(string, Func<T>, Action?)

A task that executes a callback and the provides a result. Only completion is reported, no intermediate progress.

public ResultTask(string name, Func<T> work, Action? cancellationCallback = null)

Parameters

name string

A name describing the task in human-readable form.

work Func<T>

The code to be executed by the task that provides a result. May throw System.Net.WebException, System.IO.IOException or System.OperationCanceledException.

cancellationCallback Action

An optional callback to be called when cancellation is requested via a System.Threading.CancellationToken.

Properties

CanCancel

Indicates whether this task can be canceled once it has been started.

public override bool CanCancel { get; }

Property Value

bool

Name

A name describing the task in human-readable form.

public override string Name { get; }

Property Value

string

Result

The result of the task.

public T Result { get; }

Property Value

T

Exceptions

InvalidOperationException

The task is not Complete.

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.

Exceptions

OperationCanceledException

The operation was canceled.

IOException

The task ended with IOError.

WebException

The task ended with WebError.