Export (0) Print
Expand All

DispatcherTimer.Interval Property

Gets or sets the amount of time between timer ticks.

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

public TimeSpan Interval { get; set; }

Property Value

Type: System.TimeSpan
The amount of time between ticks. The default is 00:00:00.

ExceptionCondition
ArgumentOutOfRangeException

The specified value when setting this property represents a negative time interval.

The following code example demonstrates how to use this property.


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();
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

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

Community Additions

ADD
Show:
© 2014 Microsoft