A timer that is integrated into the Dispatcher queue, which is processed at a specified interval of time and at a specified priority.
Assembly: System.Windows (in System.Windows.dll)
Thetype exposes the following members.
|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 the Object is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as a hash function for a particular type. (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 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 queue like other operations. When the operation executes is dependent on the other jobs in the queue and their priorities.
If a System.Threading.Timer is used, it is worth noting that the Timer runs on a different thread then the user interface (UI) thread. In order to access objects on the UI thread, it is necessary to post the operation onto the UI thread using Dispatcher.BeginInvoke. This is unnecessary when using a .
A will keep an object alive whenever the object's methods are bound to the timer.
The following code example demonstrates how to use this class.
Private WithEvents counterPanel As Panel Private WithEvents timer As DispatcherTimer = New DispatcherTimer() Private counter As Integer = 0 Private Sub PanelClick(ByVal sender As System.Object, _ ByVal e As System.Windows.Input.MouseButtonEventArgs) _ Handles counterPanel.MouseLeftButtonDown If timer.IsEnabled Then timer.Stop() Else timer.Start() End Sub Private Sub TimerClick(ByVal sender As System.Object, _ ByVal e As EventArgs) Handles timer.Tick counter += 1 counterPanel.Children.Clear() Dim t As New TextBlock t.Text = counter.ToString counterPanel.Children.Add(t) End Sub Private Sub TestDispatcherTimer(ByVal p As Panel) Me.counterPanel = p timer.Interval = New TimeSpan(0, 0, 1) timer.Start() End Sub
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.