NanoByte.Common  2.6.1
NanoByte.Common.Tasks.CancellationToken Struct Reference

Propagates notification that operations should be canceled. More...

Public Member Functions

CancellationTokenRegistration Register (Action callback)
 Registers a delegate that will be called when cancellation has been requested. More...
 
void ThrowIfCancellationRequested ()
 Throws an OperationCanceledException if cancellation has been requested. More...
 
override string ToString ()
 

Static Public Member Functions

static implicit operator System.Threading.CancellationToken (CancellationToken token)
 Converts a NanoByte.Common cancellation token to a regular .NET cancellation token. More...
 
static implicit operator CancellationToken (System.Threading.CancellationToken token)
 Converts a regular .NET cancellation token to a NanoByte.Common cancellation token. More...
 

Package Functions

 CancellationToken (CancellationTokenSource source)
 Creates a new token controlled by a specific CancellationTokenSource. More...
 

Properties

bool IsCancellationRequested [get]
 Indicates whether cancellation has been requested. More...
 
WaitHandle WaitHandle [get]
 Gets a wait handle that is signaled when cancellation has been requested. More...
 

Detailed Description

Propagates notification that operations should be canceled.

Unlike the built-in CancellationToken type of .NET the NanoByte.Common variant supports remoting.

Constructor & Destructor Documentation

◆ CancellationToken()

NanoByte.Common.Tasks.CancellationToken.CancellationToken ( CancellationTokenSource  source)
inlinepackage

Creates a new token controlled by a specific CancellationTokenSource.

Member Function Documentation

◆ operator CancellationToken()

static implicit NanoByte.Common.Tasks.CancellationToken.operator CancellationToken ( System.Threading.CancellationToken  token)
inlinestatic

Converts a regular .NET cancellation token to a NanoByte.Common cancellation token.

◆ operator System.Threading.CancellationToken()

static implicit NanoByte.Common.Tasks.CancellationToken.operator System.Threading.CancellationToken ( CancellationToken  token)
inlinestatic

Converts a NanoByte.Common cancellation token to a regular .NET cancellation token.

◆ Register()

CancellationTokenRegistration NanoByte.Common.Tasks.CancellationToken.Register ( Action  callback)

Registers a delegate that will be called when cancellation has been requested.

Parameters
callbackThe delegate to be executed when cancellation has been requested.
Returns
A handle that can be used to deregister the callback.

The callback is called from a background thread. Wrap via synchronization context to update UI elements. Handling this blocks the task, therefore observers should handle the event quickly.

◆ ThrowIfCancellationRequested()

void NanoByte.Common.Tasks.CancellationToken.ThrowIfCancellationRequested ( )
inline

Throws an OperationCanceledException if cancellation has been requested.

Exceptions
OperationCanceledExceptionCancellation has been requested.

Property Documentation

◆ IsCancellationRequested

bool NanoByte.Common.Tasks.CancellationToken.IsCancellationRequested
get

Indicates whether cancellation has been requested.

◆ WaitHandle

WaitHandle NanoByte.Common.Tasks.CancellationToken.WaitHandle
get

Gets a wait handle that is signaled when cancellation has been requested.


The documentation for this struct was generated from the following file: