xtd 0.2.0
Loading...
Searching...
No Matches

◆ enabled() [1/2]

bool xtd::timers::timer::enabled ( ) const
noexcept

Gets a value indicating whether the xtd::timers::timer should raise the xtd::timers::timer::elapsed event.

Returns
true if the xtd::timers::timer should raise the xtd::timers::timer::elapsed event; otherwise, false. The default is false.
Exceptions
xtd::object_closed_exceptionThis property cannot be set because the timer has been closed.
xtd::argument_exceptionThe xtd::timers::timer::interval property was set to a value greater than xtd::int32_object::max_value before the timer was enabled.
Remarks
Setting xtd::timers::timer::enabled to true is the same as calling xtd::timers::timer::start, while setting xtd::timers::timer::enabled to false is the same as calling xtd::timers::timer::stop.
Note
The signal to raise the xtd::timers::timer::elapsed event is always queued for execution on a xtd::threading::thread_pool thread. This might result in the xtd::timers::timer::elapsed event being raised after the xtd::timers::timer::enabled property is set to false. The code example for the xtd::timers::timer::stop method shows one way to work around this race condition.
Remarks
If xtd::timers::timer::enabled is set to true and xtd::timers::timer::auto_reset is set to false, the xtd::timers::timer raises the xtd::timers::timer::elapsed event only once, the first time the interval elapses.
If the interval is set after the xtd::timers::timer has started, the count is reset. For example, if you set the interval to 5 seconds and then set the xtd::timers::timer::enabled property to true, the count starts at the time xtd::timers::timer::enabled is set. If you reset the interval to 10 seconds when count is 3 seconds, the xtd::timers::timer::elapsed event is raised for the first time 13 seconds after Enabled was set to true.