A timer that is integrated into the Dispatcher queue which is processed at a specified interval of time and at a specified priority.
Assembly: WindowsBase (in WindowsBase.dll)
XMLNS for XAML: Not mapped to an xmlns.
Thetype exposes the following members.
|DispatcherTimer||Initializes a new instance of the class.|
|DispatcherTimer(DispatcherPriority)||Initializes a new instance of the class which processes timer events at the specified priority.|
|DispatcherTimer(DispatcherPriority, Dispatcher)||Initializes a new instance of the class which runs on the specified Dispatcher at the specified priority.|
|DispatcherTimer(TimeSpan, DispatcherPriority, EventHandler, Dispatcher)||Initializes a new instance of the class which uses the specified time interval, priority, event handler, and Dispatcher.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Start||Starts the .|
|Stop||Stops the .|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
The is reevaluated at the top of every Dispatcher loop.
Timers are not guaranteed to execute exactly when the time interval occurs, but they are guaranteed to not execute before the time interval occurs. This is because operations are placed on the Dispatcher queue like other operations. When the operation executes is dependent on the other jobs in the queue and their priorities.
If a System.Timers.Timer is used in a WPF application, it is worth noting that the System.Timers.Timer runs on a different thread then the user interface (UI) thread. In order to access objects on the user interface (UI) thread, it is necessary to post the operation onto the Dispatcher of the user interface (UI) thread using Invoke or BeginInvoke. Reasons for using a opposed to a System.Timers.Timer are that the runs on the same thread as the Dispatcher and a DispatcherPriority can be set on the .
A will keep an object alive whenever the object's methods are bound to the timer.
A object named dispatcherTimer is created. The event handler dispatcherTimer_Tick is added to the Tick event of dispatcherTimer. The Interval is set to 1 second using a TimeSpan object, and the timer is started.
' System.Windows.Threading.DispatcherTimer.Tick handler ' ' Updates the current seconds display and calls ' InvalidateRequerySuggested on the CommandManager to force ' the Command to raise the CanExecuteChanged event. Private Sub dispatcherTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) ' Updating the Label which displays the current second lblSeconds.Content = Date.Now.Second ' Forcing the CommandManager to raise the RequerySuggested event CommandManager.InvalidateRequerySuggested() End Sub