cancellation_token Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

The cancellation_token class represents the ability to determine whether some operation has been requested to cancel. A given token can be associated with a task_group, structured_task_group, or task to provide implicit cancellation. It can also be polled for cancellation or have a callback registered for if and when the associated cancellation_token_source is canceled.

class cancellation_token;

Public Constructors

NameDescription
cancellation_token::cancellation_token Constructor
cancellation_token::~cancellation_token Destructor

Public Methods

NameDescription
cancellation_token::deregister_callback MethodRemoves a callback previously registered via the register method based on the cancellation_token_registration object returned at the time of registration.
cancellation_token::is_cancelable MethodReturns an indication of whether this token can be canceled or not.
cancellation_token::is_canceled MethodReturns true if the token has been canceled.
cancellation_token::none MethodReturns a cancellation token which can never be subject to cancellation.
cancellation_token::register_callback MethodRegisters a callback function with the token. If and when the token is canceled, the callback will be made. Note that if the token is already canceled at the point where this method is called, the callback will be made immediately and synchronously.

Public Operators

NameDescription
cancellation_token::operator!= Operator
cancellation_token::operator= Operator
cancellation_token::operator== Operator

cancellation_token

Header: pplcancellation_token.h

Namespace: concurrency

~cancellation_token();

cancellation_token(const cancellation_token& _Src);

cancellation_token(cancellation_token&& _Src);

Parameters

_Src

Removes a callback previously registered via the register method based on the cancellation_token_registration object returned at the time of registration.

void deregister_callback(const cancellation_token_registration& _Registration) const;

Parameters

_Registration
The cancellation_token_registration object corresponding to the callback to be deregistered. This token must have been previously returned from a call to the register method.

Returns an indication of whether this token can be canceled or not.

bool is_cancelable() const;

Return Value

An indication of whether this token can be canceled or not.

Returns true if the token has been canceled.

bool is_canceled() const;

Return Value

The value true if the token has been canceled; otherwise, the value false.

Returns a cancellation token which can never be subject to cancellation.

static cancellation_token none();

Return Value

A cancellation token that cannot be canceled.

bool operator!= (const cancellation_token& _Src) const;

Parameters

_Src

Return Value

cancellation_token& operator= (const cancellation_token& _Src);

cancellation_token& operator= (cancellation_token&& _Src);

Parameters

_Src

Return Value

bool operator== (const cancellation_token& _Src) const;

Parameters

_Src

Return Value

Registers a callback function with the token. If and when the token is canceled, the callback will be made. Note that if the token is already canceled at the point where this method is called, the callback will be made immediately and synchronously.

template<typename _Function>
::Concurrency::cancellation_token_registration register_callback(const _Function& _Func) const;

Parameters

_Function
The type of the function object that will be called back when this cancellation_token is canceled.

_Func
The function object that will be called back when this cancellation_token is canceled.

Return Value

A cancellation_token_registration object which can be utilized in the deregister method to deregister a previously registered callback and prevent it from being made. The method will throw an invalid_operation exception if it is called on a cancellation_token object that was created using the cancellation_token::none method.

concurrency Namespace

Show: