Table of Contents

Class TaskBase

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

Abstract base class for ITask implementations.

public abstract class TaskBase : MarshalByRefObject, ITask
Inheritance
TaskBase
Implements
Derived
Extension Methods

Fields

CancellationToken

Signaled when the user wants to cancel the task execution.

protected CancellationToken CancellationToken

Field Value

CancellationToken

CredentialProvider

Used to retrieve credentials for specific Uris on demand; can be null.

protected ICredentialProvider? CredentialProvider

Field Value

ICredentialProvider

Properties

CanCancel

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

public virtual bool CanCancel { get; }

Property Value

bool

Name

A name describing the task in human-readable form.

public abstract string Name { get; }

Property Value

string

PreventIdle

Indicates whether this task should prevent the system from entering idle mode.

protected virtual bool PreventIdle { get; }

Property Value

bool

State

The current State of the task.

protected TaskState State { get; set; }

Property Value

TaskState

Tag

An object used to associate the task with a specific process; can be null.

public object? Tag { get; set; }

Property Value

object

UnitsByte

true if UnitsProcessed and UnitsTotal are measured in bytes; false if they are measured in generic units.

protected abstract bool UnitsByte { get; }

Property Value

bool

UnitsProcessed

The number of units that have been processed so far.

protected long UnitsProcessed { get; set; }

Property Value

long

UnitsTotal

The total number of units that are to be processed; -1 for unknown.

protected long UnitsTotal { get; set; }

Property Value

long

Methods

Execute()

The actual code to be executed.

protected abstract 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.

Run(CancellationToken, ICredentialProvider?, IProgress<TaskSnapshot>?)

Runs the task and blocks until it is complete.

public void Run(CancellationToken cancellationToken = default, ICredentialProvider? credentialProvider = null, IProgress<TaskSnapshot>? progress = null)

Parameters

cancellationToken CancellationToken

Used to receive a signal (e.g. from another thread) when the user wants to cancel the task.

credentialProvider ICredentialProvider

Object used to retrieve credentials for specific Uris on demand; can be null.

progress IProgress<TaskSnapshot>

Used to report back the task's progress (e.g. to another thread).

Exceptions

OperationCanceledException

The task was canceled from another thread.

IOException

The task ended with IOError.

WebException

The task ended with WebError.

See Also