cancellation_token 類別

cancellation_token 類別表示可判斷某個作業是否已要求取消的能力。 特定語彙基元可以與 task_groupstructured_task_grouptask 產生關聯,來提供隱含取消作業。 如果與相關聯的 cancellation_token_source 已取消,也可以向它輪詢取消,或為它註冊回呼。

語法

class cancellation_token;

成員

公用建構函式

名稱 描述
cancellation_token
~cancellation_token解構函式

公用方法

名稱 描述
deregister_callback 根據註冊時傳回的 register 物件,移除先前透過 cancellation_token_registration 方法註冊的回呼。
is_cancelable 傳回這個語彙基元是否可以取消的指示。
is_canceled 如果權杖已取消,則傳 true 回 。
none 傳回永不需取消的取消語彙基元。
register_callback 使用語彙基元註冊回呼函式。 如果這個語彙基元已取消,將會進行回呼。 請注意,如果語彙基元已經在呼叫此方法的時間點取消,將會立即同步進行回呼。

公用運算子

名稱 描述
operator!=
operator=
operator==

繼承階層架構

cancellation_token

需求

標頭: pplcancellation_token.h

命名空間: concurrency

~cancellation_token

~cancellation_token();

cancellation_token

cancellation_token(const cancellation_token& _Src);

cancellation_token(cancellation_token&& _Src);

參數

_Src
要複製或移動cancellation_token。

deregister_callback

根據註冊時傳回的 register 物件,移除先前透過 cancellation_token_registration 方法註冊的回呼。

void deregister_callback(const cancellation_token_registration& _Registration) const;

參數

_註冊
cancellation_token_registration 物件,對應於要取消註冊的回呼。 這個語彙基元必須已經由 register 方法呼叫所傳回。

is_cancelable

傳回這個語彙基元是否可以取消的指示。

bool is_cancelable() const;

傳回值

表示這個語彙基元是否可以取消。

is_canceled

如果權杖已取消,則傳 true 回 。

bool is_canceled() const;

傳回值

如果權杖已取消,則為 值 true ,否則為 值 false

none

傳回永不需取消的取消語彙基元。

static cancellation_token none();

傳回值

無法取消的取消語彙基元。

operator!=

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

參數

_Src
要比較的 cancellation_token

傳回值

operator=

cancellation_token& operator= (const cancellation_token& _Src);

cancellation_token& operator= (cancellation_token&& _Src);

參數

_Src
cancellation_token 指派的 。

傳回值

operator==

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

參數

_Src
要比較的 cancellation_token

傳回值

register_callback

使用語彙基元註冊回呼函式。 如果這個語彙基元已取消,將會進行回呼。 請注意,如果語彙基元已經在呼叫此方法的時間點取消,將會立即同步進行回呼。

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

參數

_功能
當取消這個 cancellation_token 時,會被回呼的函式物件的類型。

_Func
當取消這個 cancellation_token 時,會被回呼的函式物件。

傳回值

cancellation_token_registration 物件,可在 deregister 方法中用來取消註冊先前註冊的回呼,並防止進行此回呼。 如果在使用 cancellation_token::none 方法建立的物件上 cancellation_token 呼叫此方法,此方法將會擲回 invalid_operation 例外狀況。

另請參閱

concurrency 命名空間