Creates and controls a thread, sets its priority, and gets its status.
Public Fields | |
static const intptr | invalid_handle |
Represents an invalid native operating system handle. This field is read-only. | |
static const intptr | invalid_thread_id |
Represents an invalid native operating system thread id. This field is read-only. | |
Cosntructors | |
thread (const xtd::threading::parameterized_thread_start &start) | |
Initializes a new instance of the xtd::threading::thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started. | |
thread (const xtd::threading::parameterized_thread_start &start, int32 max_stack_size) | |
Initializes a new instance of the xtd::threading::thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started and specifying the maximum stack size for the thread. | |
thread (const xtd::threading::thread_start &start) | |
Initializes a new instance of the xtd::threading::thread class. | |
thread (const xtd::threading::thread_start &start, int32 max_stack_size) | |
Initializes a new instance of the xtd::threading::thread class, specifying the maximum stack size for the thread. | |
Public Properties | |
bool | auto_join () const noexcept |
Gets a value indicating the current thread wiil be joined when destroyed. | |
thread & | auto_join (bool value) |
Sets a value indicating the current thread wiil be joined when destroyed. | |
intptr | handle () const noexcept |
Gets the native operating system handle. | |
bool | is_alive () const noexcept |
Gets a value indicating the execution status of the current thread. | |
bool | is_background () const noexcept |
Gets a value indicating whether or not a thread is a background thread. | |
thread & | is_background (bool value) |
Sets a value indicating whether or not a thread is a background thread. | |
bool | is_main_thread () const noexcept |
Gets a value indicating the current thread is the main thread. | |
bool | is_thread_pool_thread () const noexcept |
Gets a value indicating whether or not a thread belongs to the managed thread pool. | |
bool | joinable () const noexcept |
Gets a value indicating the current thread is joinable. | |
int32 | managed_thread_id () const noexcept |
Gets a unique identifier for the current managed thread. | |
string | name () const noexcept |
Gets the name of the thread. | |
thread & | name (const string &value) |
Sets the name of the thread. | |
xtd::threading::thread_priority | priority () const noexcept |
Gets a value indicating the scheduling priority of a thread. | |
thread & | priority (xtd::threading::thread_priority value) |
Sets a value indicating the scheduling priority of a thread. | |
intptr | thread_id () const noexcept |
Gets the native operating system thread id. | |
xtd::threading::thread_state | thread_state () const noexcept |
Gets a value containing the states of the current thread. | |
Public Methods | |
void | abort () |
Raises a xtd::threading::thread_aborted_exception in the thread on which it is invoked, to begin the process of terminating the thread. Calling this method usually terminates the thread. | |
void | detach () |
Sets the thread background. | |
void | interrupt () |
Interrupts a thread that is in the xtd::threading::thread_state::wait_sleep_join thread state. | |
void | join () |
Blocks the calling thread until this thread object terminates, while continuing to perform standard COM and SendMessage pumping. | |
bool | join (int32 milliseconds_timeout) |
Blocks the calling thread until this thread object terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping. | |
bool | join (const time_span &timeout) |
Blocks the calling thread until this thread object terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping. | |
void | resume () |
Resumes a thread that has been suspended (Should not be used). | |
void | start () |
Causes the operating system to change the state of the current instance to xtd::threading::thread_state::running. | |
void | start (std::any obj) |
Causes the operating system to change the state of the current instance to xtd::threading::thread_state::running. | |
void | suspend () |
Either suspends the thread, or if the thread is already suspended, has no effect (Should not be used). | |
Public Static Properties | |
static thread & | current_thread () noexcept |
Gets the currently running thread. | |
static thread & | main_thread () |
Gets the main thread. | |
Public Static Methods | |
static thread | start_new (const xtd::threading::thread_start &start) |
Create and immedialtely start a xtd::threading::thread with specified method. | |
static thread | start_new (const xtd::threading::parameterized_thread_start &start, std::any obj) |
Create and immedialtely start a xtd::threading::thread with specified method. | |
static void | join_all () |
Blocks the calling thread until all joinable threads terminate. | |
static bool | join_all (int32 milliseconds_timeout) |
Blocks the calling thread until all joinable threads terminate or the specified time elapses, while continuing. | |
static bool | join_all (const time_span &timeout) |
Blocks the calling thread until all joinable threads terminate or the specified time elapses, while continuing. | |
template<typename collection_t > | |
static void | join_all (const collection_t &threads) |
Blocks the calling thread until all specified joinable threads collection terminate. | |
template<typename collection_t > | |
static bool | join_all (const collection_t &threads, int32 milliseconds_timeout) |
Blocks the calling thread until all specified joinable threads collection terminate or the specified time elapses, while continuing. | |
template<typename collection_t > | |
static bool | join_all (const collection_t &threads, const time_span &timeout) |
Blocks the calling thread until all specified joinable threads collection terminate or the specified time elapses, while continuing. | |
static void | sleep (int32 milliseconds_timeout) |
Suspends the current thread for a specified time. | |
static void | sleep (const time_span &timeout) |
Suspends the current thread for a specified time. | |
static void | spin_wait (int32 iterations) |
Causes a thread to wait the number of times defined by the iterations parameter. | |
static bool | yield () |
Causes the calling thread to yield execution to another thread that is ready to run on the current processor. The operating system selects the thread to yield to. | |
Additional Inherited Members | |
Public Member Functions inherited from xtd::object | |
object ()=default | |
Create a new instance of the ultimate base class object. | |
virtual bool | equals (const object &obj) const noexcept |
Determines whether the specified object is equal to the current object. | |
virtual size_t | get_hash_code () const noexcept |
Serves as a hash function for a particular type. | |
virtual type_object | get_type () const noexcept |
Gets the type of the current instance. | |
template<typename object_t > | |
xtd::uptr< 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. | |
Static Public Member Functions inherited from xtd::object | |
template<typename object_a_t , typename 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<typename object_a_t , typename 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. | |
|
explicit |
Initializes a new instance of the xtd::threading::thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started.
start | A delegate that represents the methods to be invoked when this thread begins executing. |
xtd::argument_exception | The start parameter is empty. |
xtd::threading::thread::thread | ( | const xtd::threading::parameterized_thread_start & | start, |
int32 | max_stack_size | ||
) |
Initializes a new instance of the xtd::threading::thread class, specifying a delegate that allows an object to be passed to the thread when the thread is started and specifying the maximum stack size for the thread.
start | A delegate that represents the methods to be invoked when this thread begins executing. |
max_stack_size | The maximum stack size, in bytes, to be used by the thread, or 0 to use the default maximum stack size specified in the header for the executable. Important For partially trusted code, max_stack_size is ignored if it is greater than the default stack size. No exception is thrown. |
xtd::argument_exception | The start parameter is empty. |
|
explicit |
Initializes a new instance of the xtd::threading::thread class.
start | A xtd::threading::thread_start delegate that represents the methods to be invoked when this thread begins executing. |
max_stack_size | The maximum stack size, in bytes, to be used by the thread, or 0 to use the default maximum stack size specified in the header for the executable. Important For partially trusted code, max_stack_size is ignored if it is greater than the default stack size. No exception is thrown. |
xtd::argument_exception | The start parameter is empty. |
xtd::threading::thread::thread | ( | const xtd::threading::thread_start & | start, |
int32 | max_stack_size | ||
) |
Initializes a new instance of the xtd::threading::thread class, specifying the maximum stack size for the thread.
start | A xtd::threading::thread_start delegate that represents the methods to be invoked when this thread begins executing. |
max_stack_size | The maximum stack size, in bytes, to be used by the thread, or 0 to use the default maximum stack size specified in the header for the executable. Important For partially trusted code, max_stack_size is ignored if it is greater than the default stack size. No exception is thrown. |
xtd::argument_exception | The start parameter is empty. |
|
noexcept |
Gets a value indicating the current thread wiil be joined when destroyed.
thread & xtd::threading::thread::auto_join | ( | bool | value | ) |
Sets a value indicating the current thread wiil be joined when destroyed.
value | true if this thread will be joined when destroyed; otherwise, false. |
|
noexcept |
Gets the native operating system handle.
|
noexcept |
Gets a value indicating the execution status of the current thread.
|
noexcept |
Gets a value indicating whether or not a thread is a background thread.
xtd::threadng::thread_state_exception | The thread is dead. |
thread & xtd::threading::thread::is_background | ( | bool | value | ) |
Sets a value indicating whether or not a thread is a background thread.
value | true if this thread is or is to become a background thread; otherwise, false. |
xtd::threadng::thread_state_exception | The thread is dead. |
|
noexcept |
Gets a value indicating the current thread is the main thread.
|
noexcept |
Gets a value indicating whether or not a thread belongs to the managed thread pool.
|
noexcept |
Gets a value indicating the current thread is joinable.
|
noexcept |
Gets a unique identifier for the current managed thread.
|
noexcept |
Gets the name of the thread.
Sets the name of the thread.
value | A string containing the name of the thread, or empty ("") if no name was set. |
|
noexcept |
Gets a value indicating the scheduling priority of a thread.
xtd::threading::thread_state_exception | The thread has reached a final state, such as Aborted. |
xtd::argument_exception | The value specified for a set operation is not a valid xtd::threading::thread_priority value. |
thread & xtd::threading::thread::priority | ( | xtd::threading::thread_priority | value | ) |
Sets a value indicating the scheduling priority of a thread.
value | One of the xtd::threading::thread_priority values. The default value is xtd::threading::thread_priority::normal. |
xtd::threading::thread_state_exception | The thread has reached a final state, such as Aborted. |
xtd::argument_exception | The value specified for a set operation is not a valid xtd::threading::thread_priority value. |
|
noexcept |
Gets the native operating system thread id.
|
noexcept |
Gets a value containing the states of the current thread.
|
staticnoexcept |
Gets the currently running thread.
|
static |
Gets the main thread.
void xtd::threading::thread::abort | ( | ) |
Raises a xtd::threading::thread_aborted_exception in the thread on which it is invoked, to begin the process of terminating the thread. Calling this method usually terminates the thread.
xtd::threading::thread_aborted_exception | The thread that is being aborted is currently suspended. |
void xtd::threading::thread::detach | ( | ) |
Sets the thread background.
void xtd::threading::thread::interrupt | ( | ) |
Interrupts a thread that is in the xtd::threading::thread_state::wait_sleep_join thread state.
void xtd::threading::thread::join | ( | ) |
Blocks the calling thread until this thread object terminates, while continuing to perform standard COM and SendMessage pumping.
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
bool xtd::threading::thread::join | ( | int32 | milliseconds_timeout | ) |
Blocks the calling thread until this thread object terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping.
milliseconds_timeout | The number of milliseconds to wait for the thread to terminate. |
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
xtd::argument_out_of_range_rxception | milliseconds_timeout is a negative number other than -1, which represents an infinite time-out. |
bool xtd::threading::thread::join | ( | const time_span & | timeout | ) |
Blocks the calling thread until this thread object terminates or the specified time elapses, while continuing to perform standard COM and SendMessage pumping.
timeout | A xtd::time_span set to the amount of time to wait for the thread to terminate. |
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
xtd::argument_exception | timeout is a negative number other than -1 milliseconds, which represents -or- timeout is greater than xtd::int32_object::max_value. |
void xtd::threading::thread::resume | ( | ) |
Resumes a thread that has been suspended (Should not be used).
xtd::threading::thread_state_exception | The thread has not been started, is dead, or is not in the suspended state. |
void xtd::threading::thread::start | ( | ) |
Causes the operating system to change the state of the current instance to xtd::threading::thread_state::running.
xtd::threading::thread_state_exception | The thread has already been started. |
void xtd::threading::thread::start | ( | std::any | obj | ) |
Causes the operating system to change the state of the current instance to xtd::threading::thread_state::running.
obj | An object that contains data to be used by the method the thread executes. |
xtd::threading::thread_state_exception | The thread has already been started. |
void xtd::threading::thread::suspend | ( | ) |
Either suspends the thread, or if the thread is already suspended, has no effect (Should not be used).
xtd::threading::thread_state_exception | The thread has not been started or is dead. |
|
static |
Create and immedialtely start a xtd::threading::thread with specified method.
start | A delegate that represents the methods to be invoked when this thread begins executing. |
xtd::argument_exception | The start parameter is empty. |
|
static |
Create and immedialtely start a xtd::threading::thread with specified method.
start | A delegate that represents the methods to be invoked when this thread begins executing. |
obj | An object that contains data to be used by the method the thread executes. |
xtd::argument_exception | The start parameter is empty. |
|
static |
Blocks the calling thread until all joinable threads terminate.
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
|
static |
Blocks the calling thread until all joinable threads terminate or the specified time elapses, while continuing.
milliseconds_timeout | The number of milliseconds to wait for all threads to terminate. |
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
|
static |
Blocks the calling thread until all joinable threads terminate or the specified time elapses, while continuing.
timeout | A xtd::time_span set to the amount of time to wait for all threads to terminate. |
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
|
inlinestatic |
Blocks the calling thread until all specified joinable threads collection terminate.
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
|
inlinestatic |
Blocks the calling thread until all specified joinable threads collection terminate or the specified time elapses, while continuing.
milliseconds_timeout | The number of milliseconds to wait for all threads to terminate. |
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
|
inlinestatic |
Blocks the calling thread until all specified joinable threads collection terminate or the specified time elapses, while continuing.
timeout | A xtd::time_span set to the amount of time to wait for all threads to terminate. |
xtd::threading::thread_state_exception | The caller attempted to join a thread that is in the xtd::threading::thread_state::unstarted state. |
|
static |
Suspends the current thread for a specified time.
milliseconds_timeout | The number of milliseconds for which the thread is blocked. Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute. Specify xtd::threading::Timeout.Infinite to block the thread indefinitely. |
xtd::argument_exception | milliseconds_timeout is a negative number other than -1, which represents an infinite time-out. |
|
static |
Suspends the current thread for a specified time.
timeout | A std::chrono::duration set to the amount of time for which the thread is blocked. Specify zero to indicate that this thread should be suspended to allow other waiting threads to execute. Specify xtd::threading::Timeout.Infinite to block the thread indefinitely. |
xtd::argument_exception | The value of timeout is negative and is not equal to xtd::threading::timeout::infinite in milliseconds, or is greater than xtd::Int32.MaxValue milliseconds. |
|
static |
Causes a thread to wait the number of times defined by the iterations parameter.
iterations | A 32-bit signed integer that defines how long a thread is to wait. |
|
static |
Causes the calling thread to yield execution to another thread that is ready to run on the current processor. The operating system selects the thread to yield to.
|
static |
Represents an invalid native operating system handle. This field is read-only.
|
static |
Represents an invalid native operating system thread id. This field is read-only.