Propagates notification that operations should be canceled.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
cancellation_token(bool canceled)
Initializes the xtd::threading::cancellation_token.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
- Inheritance
- xtd::object → xtd::threading::cancellation_token
- Header
#include <xtd/threading/cancellation_token>
- Namespace
- xtd::threading
- Library
- xtd.core
- Examples
- The following example uses a random number generator to emulate a data collection application that reads 10 integral values from eleven different instruments. A value of zero indicates that the measurement has failed for one instrument, in which case the operation should be cancelled and no overall mean should be computed. To handle the possible cancellation of the operation, the example instantiates a xtd::threading::cancellation_token_source object that generates a cancellation token that's passed to a xtd::threading::tasks::task_factory object. In turn, the xtd::threading::tasks::task_factory object passes the cancellation token to each of the tasks responsible for collecting readings for a particular instrument. The xtd::threading::tasks::task_factory::continue_when_all<antecedent_result_t,result_t>(xtd::array<xtd::threading::tasks::task<antecedent_result_t>>, xtd::func<xtd::array<xtd::threading::tasks::task<antecedent_tesult_t>>,TResult>, cancellation_token) method is called to ensure that the mean is computed only after all readings have been gathered successfully. If a task has not completed because it was cancelled, the xtd::threading::tasks::task_factory::continue_when_all method throws an exception.
|
| object ()=default |
| Create a new instance of the ultimate base class object.
|
|
virtual type_object | get_type () const noexcept |
| Gets the type of the current instance.
|
|
template<class object_t> |
xtd::unique_ptr_object< object_t > | memberwise_clone () const |
| Creates a shallow copy of the current object.
|
|
virtual xtd::string | to_string () const noexcept |
| Returns a xtd::string that represents the current object.
|
|
virtual bool | equals (const cancellation_token &) const noexcept=0 |
| Indicates whether the current object is equal to another object of the same type.
|
|
template<class object_a_t, class object_b_t> |
static bool | equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
| Determines whether the specified object instances are considered equal.
|
|
template<class object_a_t, class object_b_t> |
static bool | reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
| Determines whether the specified object instances are the same instance.
|
|
◆ cancellation_token()
xtd::threading::cancellation_token::cancellation_token |
( |
bool | canceled | ) |
|
◆ can_be_canceled()
bool xtd::threading::cancellation_token::can_be_canceled |
( |
| ) |
const |
|
noexcept |
Gets whether this token is capable of being in the canceled state.
- Returns
true
if this token is capable of being in the canceled state; otherwise, false
.
◆ is_cancellation_requested()
bool xtd::threading::cancellation_token::is_cancellation_requested |
( |
| ) |
const |
|
noexcept |
Gets whether cancellation has been requested for this token.
- Returns
true
if cancellation has been requested for this token; otherwise, false
.
◆ wait_handle()
◆ equals() [1/2]
bool xtd::threading::cancellation_token::equals |
( |
const object & | obj | ) |
const |
|
overridevirtualnoexcept |
Determines whether the specified object is equal to the current object.
- Parameters
-
obj | The object to compare with the current object. |
- Returns
true
if the specified object is equal to the current object. otherwise, false
.
Reimplemented from xtd::object.
◆ equals() [2/2]
Determines whether the specified object is equal to the current object.
- Parameters
-
other | The object to compare with the current object. |
- Returns
true
if the specified object is equal to the current object. otherwise, false
.
◆ get_hash_code()
xtd::size xtd::threading::cancellation_token::get_hash_code |
( |
| ) |
const |
|
overridevirtualnoexcept |
Serves as a hash function for a particular type.
- Returns
- A hash code for the current object.
Reimplemented from xtd::object.
◆ throw_if_cancellation_requested()
void xtd::threading::cancellation_token::throw_if_cancellation_requested |
( |
| ) |
const |
◆ none
The documentation for this class was generated from the following file: