Executes an operation on a separate thread.
Public Events | |
event< background_worker, do_work_event_handler > | do_work |
Occurs when run_worker_async() is called. | |
event< background_worker, progress_changed_event_handler > | progress_changed |
Occurs when report_progress(int32) is called. | |
event< background_worker, run_worker_completed_event_handler > | run_worker_completed |
Occurs when the background operation has completed, has been canceled, or has raised an exception. | |
Public Constructors | |
background_worker () noexcept | |
Initializes a new instance of the background_worker class. | |
Public Properties | |
bool | cancellation_pending () const noexcept |
Gets a value indicating whether the application has requested cancellation of a background operation. | |
bool | is_busy () const noexcept |
Gets a value indicating whether the background_worker is running an asynchronous operation. | |
bool | worker_reports_progress () const noexcept |
Gets a value indicating whether the background_worker can report progress updates.Gets or sets a value indicating whether the background_worker can report progress updates. | |
void | worker_reports_progress (bool value) |
Sets a value indicating whether the background_worker can report progress updates.Gets or sets a value indicating whether the background_worker can report progress updates. | |
bool | worker_supports_cancellation () const noexcept |
Gets a value indicating whether the background_worker supports asynchronous cancellation. | |
void | worker_supports_cancellation (bool value) |
Gets a value indicating whether the background_worker supports asynchronous cancellation. | |
Public Methods | |
void | cancel_async () |
Requests cancellation of a pending background operation. | |
virtual void | on_do_work (do_work_event_args &e) |
Raises the background_worker::do_work event. | |
virtual void | on_progress_changed (const progress_changed_event_args &e) |
Raises the background_worker::progress_changed event. | |
virtual void | on_run_worker_completed (const run_worker_completed_event_args &e) |
Raises the background_worker::run_worker_completed event. | |
void | run_worker_async () |
Starts execution of a background operation. | |
template<typename argument_t > | |
void | run_worker_async (argument_t argument) |
Starts execution of a background operation. | |
void | report_progress (int32 percent_progress) |
Raises the ProgressChanged event. | |
void | report_progress (int32 percent_progress, std::any user_state) |
Raises the ProgressChanged event. | |
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. | |
Protected Member Functions inherited from xtd::forms::component | |
component () | |
Initialises a new instance of the component class. | |
virtual bool | can_raise_events () const noexcept |
Gets a value indicating whether the component can raise an event. | |
bool | design_mode () const noexcept |
Gets a value that indicates whether the component is currently in design mode. | |
|
noexcept |
Initializes a new instance of the background_worker class.
|
noexcept |
Gets a value indicating whether the application has requested cancellation of a background operation.
|
noexcept |
Gets a value indicating whether the background_worker is running an asynchronous operation.
|
noexcept |
Gets a value indicating whether the background_worker can report progress updates.Gets or sets a value indicating whether the background_worker can report progress updates.
void xtd::forms::background_worker::worker_reports_progress | ( | bool | value | ) |
Sets a value indicating whether the background_worker can report progress updates.Gets or sets a value indicating whether the background_worker can report progress updates.
value | true if the background_worker supports progress updates; otherwise false. The default is false. |
|
noexcept |
Gets a value indicating whether the background_worker supports asynchronous cancellation.
void xtd::forms::background_worker::worker_supports_cancellation | ( | bool | value | ) |
Gets a value indicating whether the background_worker supports asynchronous cancellation.
value | true if the background_worker supports cancellation; otherwise false. The default is false. |
void xtd::forms::background_worker::cancel_async | ( | ) |
Requests cancellation of a pending background operation.
|
virtual |
Raises the background_worker::do_work event.
e | An event_args that contains the event data. |
|
virtual |
Raises the background_worker::progress_changed event.
e | An event_args that contains the event data. |
|
virtual |
Raises the background_worker::run_worker_completed event.
e | An event_args that contains the event data. |
void xtd::forms::background_worker::run_worker_async | ( | ) |
Starts execution of a background operation.
xtd::invalid_operaton_exception | xtd::background_worker::is_busy is true; |
|
inline |
Starts execution of a background operation.
argument | A parameter for use by the background operation to be executed in the xtd::forms::background_worker::do_work event handler. |
xtd::invalid_operaton_exception | xtd::background_worker::is_busy is true; |
void xtd::forms::background_worker::report_progress | ( | int32 | percent_progress | ) |
Raises the ProgressChanged event.
percent_progress | The percentage, from 0 to 100, of the background operation that is complete. |
void xtd::forms::background_worker::report_progress | ( | int32 | percent_progress, |
std::any | user_state | ||
) |
Raises the ProgressChanged event.
percent_progress | The percentage, from 0 to 100, of the background operation that is complete. |
user_state | A unique object indicating the user state. Returned as the user_state property of the progress_changed_even_args. |
event<background_worker, do_work_event_handler> xtd::forms::background_worker::do_work |
Occurs when run_worker_async() is called.
event<background_worker, progress_changed_event_handler> xtd::forms::background_worker::progress_changed |
Occurs when report_progress(int32) is called.
event<background_worker, run_worker_completed_event_handler> xtd::forms::background_worker::run_worker_completed |
Occurs when the background operation has completed, has been canceled, or has raised an exception.