NanoByte.Common  2.4.2
Public Member Functions | Public Attributes | Package Functions | List of all members
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 ()
 

Public Attributes

bool IsCancellationRequested => (_source != null) && _source.IsCancellationRequested
 Indicates whether cancellation has been requested. More...
 
WaitHandle WaitHandle => _source?.WaitHandle ?? _dummyWaitHandle
 Gets a wait handle that is signaled when cancellation has been requested. More...
 

Package Functions

 CancellationToken (CancellationTokenSource source)
 Creates a new token controlled by a specific CancellationTokenSource. 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

◆ 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.

Member Data Documentation

◆ IsCancellationRequested

bool NanoByte.Common.Tasks.CancellationToken.IsCancellationRequested => (_source != null) && _source.IsCancellationRequested

Indicates whether cancellation has been requested.

◆ WaitHandle

WaitHandle NanoByte.Common.Tasks.CancellationToken.WaitHandle => _source?.WaitHandle ?? _dummyWaitHandle

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


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