Condividi tramite


DispatcherTimer.Stop Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Stops the DispatcherTimer.

Namespace:  System.Windows.Threading
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Sub Stop
public void Stop()

Examples

The following code example demonstrates how to use this method.

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
private void TestDispatcherTimer(Panel counterPanel)
{
    DispatcherTimer timer = new DispatcherTimer();
    int counter = 0;

    counterPanel.MouseLeftButtonDown += 
        delegate(object s, MouseButtonEventArgs args) {
            if (timer.IsEnabled) timer.Stop(); else timer.Start(); 
        };

    timer.Tick += 
        delegate(object s, EventArgs args) {
            counterPanel.Children.Clear();
            counterPanel.Children.Add( new TextBlock { 
                Text = counter++.ToString() });
        };

    timer.Interval = new TimeSpan(0, 0, 1); // one second
    timer.Start();
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.