Class DispatcherTimer
A timer that is integrated into the Dispatcher queues, and will be processed after a given amount of time at a specified priority.
public class DispatcherTimer
- Inheritance
-
DispatcherTimer
- Inherited Members
Constructors
DispatcherTimer()
Creates a timer that uses theUI thread's Dispatcher2 to process the timer event at background priority.
public DispatcherTimer()
DispatcherTimer(DispatcherPriority)
Creates a timer that uses the UI thread's Dispatcher2 to process the timer event at the specified priority.
public DispatcherTimer(DispatcherPriority priority)
Parameters
priority
DispatcherPriorityThe priority to process the timer at.
DispatcherTimer(TimeSpan, DispatcherPriority, EventHandler)
Creates a timer that uses the UI thread's Dispatcher2 to process the timer event at the specified priority after the specified timeout.
public DispatcherTimer(TimeSpan interval, DispatcherPriority priority, EventHandler callback)
Parameters
interval
TimeSpanThe interval to tick the timer after.
priority
DispatcherPriorityThe priority to process the timer at.
callback
EventHandlerThe callback to call when the timer ticks.
Properties
Dispatcher
Gets the dispatcher this timer is associated with.
public Dispatcher Dispatcher { get; }
Property Value
Interval
Gets or sets the time between timer ticks.
public TimeSpan Interval { get; set; }
Property Value
IsEnabled
Gets or sets whether the timer is running.
public bool IsEnabled { get; set; }
Property Value
Tag
Any data that the caller wants to pass along with the timer.
public object? Tag { get; set; }
Property Value
Methods
Run(Func<bool>, TimeSpan, DispatcherPriority)
Starts a new timer.
public static IDisposable Run(Func<bool> action, TimeSpan interval, DispatcherPriority priority = default)
Parameters
action
Func<bool>The method to call on timer tick. If the method returns false, the timer will stop.
interval
TimeSpanThe interval at which to tick.
priority
DispatcherPriorityThe priority to use.
Returns
- IDisposable
An IDisposable used to cancel the timer.
RunOnce(Action, TimeSpan, DispatcherPriority)
Runs a method once, after the specified interval.
public static IDisposable RunOnce(Action action, TimeSpan interval, DispatcherPriority priority = default)
Parameters
action
ActionThe method to call after the interval has elapsed.
interval
TimeSpanThe interval after which to call the method.
priority
DispatcherPriorityThe priority to use.
Returns
- IDisposable
An IDisposable used to cancel the timer.
Start()
Starts the timer.
public void Start()
Stop()
Stops the timer.
public void Stop()
Events
Tick
Occurs when the specified timer interval has elapsed and the timer is enabled.
public event EventHandler? Tick