Class DispatcherTimer
Provides a timer that is integrated into the Dispatcher queue, which is processed at a specified interval of time and at a specified priority. One scenario for this is to run code on the UI thread.
Inheritance
System.Object
DispatcherTimer
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: System.Windows.Threading
Assembly: OpenSilver.dll
Syntax
public class DispatcherTimer
Examples
Here is how you can create and use a DispatcherTimer:
DispatcherTimer _dispatcherTimer;
//We create a new instance of DispatcherTimer:
_dispatcherTimer = new Dispatchertimer();
//we set the time between each tick of the DispatcherTimer to 100 milliseconds:
timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
_dispatcherTimer.Tick += DispatcherTimer_Tick;
_dispatcherTimer.Start();
void DispatcherTimer_Tick(object sender, object e)
{
//Some code to execute at each Tick of the DispatcherTimer.
}
When you want to stop the DispatcherTimer, you can use the following code:
_dispatcherTimer.Stop();
Constructors
| Improve this Doc View SourceDispatcherTimer()
Initializes a new instance of the DispatcherTimer class.
Declaration
public DispatcherTimer()
Properties
| Improve this Doc View SourceInterval
Gets or sets the amount of time between timer ticks.
Declaration
public TimeSpan Interval { get; set; }
Property Value
Type | Description |
---|---|
System.TimeSpan |
IsEnabled
Gets a value that indicates whether the timer is running.
Declaration
public bool IsEnabled { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceOnTick()
Raises the Tick event.
Declaration
protected void OnTick()
Start()
Starts the DispatcherTimer.
Declaration
public void Start()
Stop()
Stops the DispatcherTimer.
Declaration
public void Stop()
Events
| Improve this Doc View SourceTick
Occurs when the timer interval has elapsed.
Declaration
public event EventHandler Tick
Event Type
Type | Description |
---|---|
System.EventHandler |