Table of Contents

Interface ITaskHandler

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

Used to run and track ITasks and ask the user questions. Specific implementations provide different kinds of user interfaces.

public interface ITaskHandler
Extension Methods

Remarks

Implementations of this interface are thread-safe.

Properties

CancellationToken

Used to signal when the user wants to cancel the entire current process (and any ITasks it includes).

CancellationToken CancellationToken { get; }

Property Value

CancellationToken

Remarks

Once this has been signalled this ITaskHandler cannot be reused, since any subsequently started ITasks will be cancelled immediately.

Verbosity

The detail level of messages displayed to the user.

Verbosity Verbosity { get; set; }

Property Value

Verbosity

Methods

Ask(string, bool?, string?)

Asks the user a Yes/No/Cancel question.

bool Ask(string question, bool? defaultAnswer = null, string? alternateMessage = null)

Parameters

question string

The question and comprehensive information to help the user make an informed decision.

defaultAnswer bool?

The default answer to preselect. May be chosen automatically if the user cannot be asked. null if the user must make the choice themselves.

alternateMessage string

A message to output with Warn(string, Exception?) when the defaultAnswer is used instead of asking the user.

Returns

bool

true if the user answered with 'Yes'; false if the user answered with 'No'.

Exceptions

OperationCanceledException

Throw if the user answered with 'Cancel' or if no answer can be obtained.

Error(Exception)

Displays an error message to the user.

void Error(Exception exception)

Parameters

exception Exception

The exception representing the error that occurred.

Output(string, string)

Displays multi-line text to the user.

void Output(string title, string message)

Parameters

title string

A title for the message.

message string

The string to display. Trailing linebreaks are appropriately handled or ignored.

Remarks

Implementations may close the UI as a side effect. Therefore this should be your last call on the handler.

Output<T>(string, NamedCollection<T>)

Displays tree-like data to the user.

void Output<T>(string title, NamedCollection<T> data) where T : INamed

Parameters

title string

A title for the data.INamed

data NamedCollection<T>

The data to display.

Type Parameters

T

Remarks

Implementations may close the UI as a side effect. Therefore this should be your last call on the handler.

Output<T>(string, IEnumerable<T>)

Displays tabular data to the user.

void Output<T>(string title, IEnumerable<T> data)

Parameters

title string

A title for the data.

data IEnumerable<T>

The data to display.

Type Parameters

T

Remarks

Implementations may close the UI as a side effect. Therefore this should be your last call on the handler.

RunTask(ITask)

Runs an ITask and tracks its progress. Returns once the task has been completed.

void RunTask(ITask task)

Parameters

task ITask

The task to be run. (Run(CancellationToken, ICredentialProvider?, IProgress<TaskSnapshot>?) or equivalent is called on it.)

Exceptions

OperationCanceledException

The user canceled the task.

IOException

The task ended with IOError.

WebException

The task ended with WebError.