Class TaskBase
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
CredentialProvider
Used to retrieve credentials for specific Uris on demand; can be null
.
protected ICredentialProvider? CredentialProvider
Field Value
Properties
CanCancel
Indicates whether this task can be canceled once it has been started.
public virtual bool CanCancel { get; }
Property Value
Name
A name describing the task in human-readable form.
public abstract string Name { get; }
Property Value
PreventIdle
Indicates whether this task should prevent the system from entering idle mode.
protected virtual bool PreventIdle { get; }
Property Value
State
The current State of the task.
protected TaskState State { get; set; }
Property Value
Tag
An object used to associate the task with a specific process; can be null
.
public object? Tag { get; set; }
Property Value
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
UnitsProcessed
The number of units that have been processed so far.
protected long UnitsProcessed { get; set; }
Property Value
UnitsTotal
The total number of units that are to be processed; -1 for unknown.
protected long UnitsTotal { get; set; }
Property Value
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
CancellationTokenUsed to receive a signal (e.g. from another thread) when the user wants to cancel the task.
credentialProvider
ICredentialProviderObject 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