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

◆ interval() [2/2]

timer & xtd::timers::timer::interval ( double  value)

Sets the interval, expressed in milliseconds, at which to raise the xtd::timers::timer::elapsed event.

Parameters
valueThe time, in milliseconds, between xtd::timers::timer::elapsed events. The value must be greater than zero, and less than or equal to xtd::int32_object::max_value. The default is 100 milliseconds.
Exceptions
xtd::argument_exceptionThe interval is less than or equal to zero.
-or
The interval is greater than xtd::int32_object::max_value.
Remarks
You use the xtd::timers::timer::interval property to determine the frequency at which the xtd::timers::timer::elapsed event is fired. Because the xtd::timers::timer class depends on the system clock, it has the same resolution as the system clock. This means that the xtd::timers::timer::elapsed event will fire at an interval defined by the resolution of the system clock if the xtd::timers::timer::interval property is less than the resolution of the system clock. The following example sets the xtd::timers::timer::interval property to 5 milliseconds. When run on a Windows system whose system clock has a resolution of approximately 15 milliseconds, the event fires approximately every 15 milliseconds rather than every 5 milliseconds.
Note
The system clock that is used is the same clock used by GetTickCount, which is not affected by changes made with timeBeginPeriod and timeEndPeriod.
Remarks
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 xtd::timers::timer::enabled was set to true.
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. xtd::timers::timer::enabled is then set to false.
Note
If xtd::timers::timer::enabled and xtd::timers::timer::auto_reset are both set to false, and the timer has previously been enabled, setting the xtd::timers::timer::interval property causes the xtd::timers::timer::elapsed event to be raised once, as if the xtd::timers::timer::enabled property had been set to true. To set the interval without raising the event, you can temporarily set the xtd::timers::timer::enabled property to true, set the xtd::timers::timer::interval property to the desired time interval, and then immediately set the xtd::timers::timer::enabled property back to false.