Skip to main content

DispatcherTimer Class

Definition

Assembly:Avalonia.Base
Package:Avalonia

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: object -> DispatcherTimer

Constructors

NameDescription
DispatcherTimer (3 overloads)Creates a timer that uses theUI thread's Dispatcher2 to process the timer event at background priority.

DispatcherTimer overloads

DispatcherTimer Constructor

Creates a timer that uses theUI thread's Dispatcher2 to process the timer event at background priority.

public DispatcherTimer()

DispatcherTimer Constructor

Creates a timer that uses the UI thread's Dispatcher2 to process the timer event at the specified priority.

public DispatcherTimer(Avalonia.Threading.DispatcherPriority priority)
Parameters

priority Avalonia.Threading.DispatcherPriority

The priority to process the timer at.

DispatcherTimer Constructor

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, Avalonia.Threading.DispatcherPriority priority, EventHandler callback)
Parameters

interval TimeSpan

The interval to tick the timer after.

priority Avalonia.Threading.DispatcherPriority

The priority to process the timer at.

callback EventHandler

The callback to call when the timer ticks.

Methods

NameDescription
RunNo summary available.
RunOnceRuns a method once, after the specified interval.
StartStarts the timer.
StopStops the timer.

Run Method

public IDisposable Run(Func<bool> action, TimeSpan interval, Avalonia.Threading.DispatcherPriority priority)

Parameters

action Func<bool>

interval TimeSpan

priority Avalonia.Threading.DispatcherPriority

Returns

IDisposable

RunOnce Method

Runs a method once, after the specified interval.

public IDisposable RunOnce(Action action, TimeSpan interval, Avalonia.Threading.DispatcherPriority priority)

Parameters

action Action

The method to call after the interval has elapsed.

interval TimeSpan

The interval after which to call the method.

priority Avalonia.Threading.DispatcherPriority

The priority to use.

Returns

IDisposable

An IDisposable used to cancel the timer.

Start Method

Starts the timer.

public void Start()

Stop Method

Stops the timer.

public void Stop()

Properties

NameDescription
DispatcherGets the dispatcher this timer is associated with.
IntervalGets or sets the time between timer ticks.
IsEnabledGets or sets whether the timer is running.
TagAny data that the caller wants to pass along with the timer.

Dispatcher Property

Gets the dispatcher this timer is associated with.

public Avalonia.Threading.Dispatcher Dispatcher { get; set; }

Interval Property

Gets or sets the time between timer ticks.

public TimeSpan Interval { get; set; }

IsEnabled Property

Gets or sets whether the timer is running.

public bool IsEnabled { get; set; }

Tag Property

Any data that the caller wants to pass along with the timer.

public object Tag { get; set; }

Events

NameDescription
TickOccurs when the specified timer interval has elapsed and the timer is enabled.

Tick Event

Occurs when the specified timer interval has elapsed and the timer is enabled.

public event EventHandler Tick