Show / Hide Table of Contents

Class TaskBase

Abstract base class for ITask implementations.

Inheritance
Object
TaskBase
DownloadFile
ReadDirectoryBase
ReadFile
ForEachTask<T>
SimplePercentTask
SimpleTask
WaitTask
Implements
ITask
Namespace: NanoByte.Common.Tasks
Assembly: NanoByte.Common.dll
Syntax
public abstract class TaskBase : MarshalByRefObject, ITask

Constructors

TaskBase()

Declaration
protected TaskBase()

Fields

CancellationToken

Signaled when the user wants to cancel the task execution.

Declaration
protected CancellationToken CancellationToken
Field Value
Type Description
CancellationToken

CredentialProvider

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

Declaration
protected ICredentialProvider CredentialProvider
Field Value
Type Description
ICredentialProvider

Properties

CanCancel

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

Declaration
public virtual bool CanCancel { get; }
Property Value
Type Description
Boolean

Name

A name describing the task in human-readable form.

Declaration
public abstract string Name { get; }
Property Value
Type Description
String

PreventIdle

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

Declaration
protected virtual bool PreventIdle { get; }
Property Value
Type Description
Boolean

State

The current State of the task.

Declaration
protected TaskState State { get; set; }
Property Value
Type Description
TaskState

Tag

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

Declaration
public object Tag { get; set; }
Property Value
Type Description
Object

UnitsByte

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

Declaration
protected abstract bool UnitsByte { get; }
Property Value
Type Description
Boolean

UnitsProcessed

The number of units that have been processed so far.

Declaration
protected long UnitsProcessed { get; set; }
Property Value
Type Description
Int64

UnitsTotal

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

Declaration
protected long UnitsTotal { get; set; }
Property Value
Type Description
Int64

Methods

Execute()

The actual code to be executed.

Declaration
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
Type Condition
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.

Declaration
public void Run(CancellationToken cancellationToken = null, ICredentialProvider credentialProvider = null, IProgress<TaskSnapshot> progress = null)
Parameters
Type Name Description
CancellationToken cancellationToken

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

ICredentialProvider credentialProvider

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

IProgress<TaskSnapshot> progress

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

Exceptions
Type Condition
OperationCanceledException

The task was canceled from another thread.

IOException

The task ended with IOError.

WebException

The task ended with WebError.

See Also
RunTask(ITask)

Implements

ITask

Extension Methods

UpdateUtils.To<TIn, TOut>(TIn, Func<TIn, TOut>)
JsonStorage.SaveJson<T>(T, Stream)
JsonStorage.SaveJson<T>(T, String)
JsonStorage.ToJsonString<T>(T)
JsonStorage.ReparseAsJson<T>(Object)
JsonStorage.ReparseAsJson<T>(Object, T)
XmlStorage.SaveXml(Object, Stream, String)
XmlStorage.SaveXml<T>(T, String, String)
XmlStorage.ToXmlString(Object, String)
ConversionUtils.ConvertToString<TType>(TType)
In This Article
Back to top Copyright Bastian Eicher