Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Interval Property
Collapse the table of content
Expand the table of content

Timer.Interval Property

Gets or sets the interval, expressed in milliseconds, at which to raise the Elapsed event.

Namespace:  System.Timers
Assembly:  System (in System.dll)

public double Interval { get; set; }

Property Value

Type: System.Double
The time, in milliseconds, between Elapsed events. The value must be greater than zero, and less than or equal to Int32.MaxValue. The default is 100 milliseconds.


The interval is less than or equal to zero.


The interval is greater than Int32.MaxValue, and the timer is currently enabled. (If the timer is not currently enabled, no exception is thrown until it becomes enabled.)

You use the Interval property to determine the frequency at which the Elapsed event is fired. Because the Timer class depends on the system clock, it has the same resolution as the system clock. This means that the Elapsed event will fire at an interval defined by the resolution of the system clock if the Interval property is less than the resolution of the system clock. The following example sets the Interval property to 5 milliseconds. When run on a Windows 7 system whose system clock has a resolution of approximately 15 milliseconds, the event fires approximately every 15 milliseconds rather than every 5 milliseconds.

using System;
using System.IO;
using System.Collections.Generic;
using System.Timers;

public class Example
   private static Timer aTimer;
   private static List<String> eventlog;
   private static int nEventsFired = 0;
   private static DateTime previousTime;

   public static void Main()
        eventlog = new List<String>();

        StreamWriter sr = new StreamWriter(@".\Interval.txt");
        // Create a timer with a five millisecond interval.
        aTimer = new Timer(5);
        aTimer.Elapsed += OnTimedEvent;
        // Hook up the Elapsed event for the timer. 
        aTimer.AutoReset = true;
        sr.WriteLine("The timer should fire every {0} milliseconds.", 
        aTimer.Enabled = true;

        Console.WriteLine("Press the Enter key to exit the program... ");
        foreach (var item in eventlog)
        Console.WriteLine("Terminating the application...");

    private static void OnTimedEvent(Object source, ElapsedEventArgs e)
        eventlog.Add(String.Format("Elapsed event at {0:HH':'mm':'ss.ffffff} ({1})", 
                                   nEventsFired++ == 0 ? 
                                      0.0 : (e.SignalTime - previousTime).TotalMilliseconds));
        previousTime = e.SignalTime;
        if (nEventsFired == 20) {
           Console.WriteLine("No more events will fire...");
           aTimer.Enabled = false;
// The example writes output like the following to a file: 
//       The timer should fire every 5 milliseconds. 
//       Elapsed event at 08:42:49.370344 (0) 
//       Elapsed event at 08:42:49.385345 (15.0015) 
//       Elapsed event at 08:42:49.400347 (15.0015) 
//       Elapsed event at 08:42:49.415348 (15.0015) 
//       Elapsed event at 08:42:49.430350 (15.0015) 
//       Elapsed event at 08:42:49.445351 (15.0015) 
//       Elapsed event at 08:42:49.465353 (20.002) 
//       Elapsed event at 08:42:49.480355 (15.0015) 
//       Elapsed event at 08:42:49.495356 (15.0015) 
//       Elapsed event at 08:42:49.510358 (15.0015) 
//       Elapsed event at 08:42:49.525359 (15.0015) 
//       Elapsed event at 08:42:49.540361 (15.0015) 
//       Elapsed event at 08:42:49.555362 (15.0015) 
//       Elapsed event at 08:42:49.570364 (15.0015) 
//       Elapsed event at 08:42:49.585365 (15.0015) 
//       Elapsed event at 08:42:49.605367 (20.002) 
//       Elapsed event at 08:42:49.620369 (15.0015) 
//       Elapsed event at 08:42:49.635370 (15.0015) 
//       Elapsed event at 08:42:49.650372 (15.0015) 
//       Elapsed event at 08:42:49.665373 (15.0015)

You can use the following code to determine the resolution of the system clock on the current system:

using System;
using System.Runtime.InteropServices;

public class Example
   [DllImport("kernel32.dll", SetLastError=true)]
   static extern bool GetSystemTimeAdjustment(out long lpTimeAdjustment,
                                              out long lpTimeIncrement,
                                              out bool lpTimeAdjustmentDisabled);

   public static void Main()
      long timeAdjustment, timeIncrement = 0;
      bool timeAdjustmentDisabled;

      if (GetSystemTimeAdjustment(out timeAdjustment, out timeIncrement, 
                                  out timeAdjustmentDisabled)) {
         if (! timeAdjustmentDisabled)
            Console.WriteLine("System clock resolution: {0:N3} milliseconds", 
            Console.WriteLine("Unable to determine system clock resolution.");                     
// The example displays output like the following: 
//        System clock resolution: 15.600 milliseconds

If your app requires greater resolution than that offered by the Timer class or the system clock, use the high-resolution multimedia timers; see How to: Use the High-Resolution Timer.

If the interval is set after the Timer has started, the count is reset. For example, if you set the interval to 5 seconds and then set the Enabled property to true, the count starts at the time Enabled is set. If you reset the interval to 10 seconds when count is 3 seconds, the Elapsed event is raised for the first time 13 seconds after Enabled was set to true.

If Enabled is set to true and AutoReset is set to false, the Timer raises the Elapsed event only once, the first time the interval elapses. Enabled is then set to false.


If Enabled and AutoReset are both set to false, and the timer has previously been enabled, setting the Interval property causes the Elapsed event to be raised once, as if the Enabled property had been set to true. To set the interval without raising the event, you can temporarily set the Enabled property to true, set the Interval property to the desired time interval, and then immediately set the Enabled property back to false.

The following example instantiates a Timer object that fires its Timer.Elapsed event every two seconds (2000 milliseconds), sets up an event handler for the event, and starts the timer. The event handler displays the value of the ElapsedEventArgs.SignalTime property each time it is raised.

// Use this code inside a project created with the Visual C# > Windows Desktop > Console Application template.  
// Replace the code in Program.cs with this code.  

using System;

// To avoid confusion with other Timer classes, this sample always uses the fully-qualified 
// name of System.Timers.Timer instead of a using statement for System.Timers. 

public class Example
    private static System.Timers.Timer aTimer;

    public static void Main()
        // Normally, the timer is declared at the class level, so that it stays in scope as long as it 
        // is needed. If the timer is declared in a long-running method, KeepAlive must be used to prevent 
        // the JIT compiler from allowing aggressive garbage collection to occur before the method ends. 
        // You can experiment with this by commenting out the class-level declaration and uncommenting  
        // the declaration below; then uncomment the GC.KeepAlive(aTimer) at the end of the method.         
        //System.Timers.Timer aTimer; 

        // Create a timer and set a two second interval.
        aTimer = new System.Timers.Timer();
        aTimer.Interval = 2000;

        // Alternate method: create a Timer with an interval argument to the constructor. 
        //aTimer = new System.Timers.Timer(2000); 

        // Create a timer with a two second interval.
        aTimer = new System.Timers.Timer(2000);

        // Hook up the Elapsed event for the timer. 
        aTimer.Elapsed += OnTimedEvent;

        // Have the timer fire repeated events (true is the default)
        aTimer.AutoReset = true;

        // Start the timer
        aTimer.Enabled = true;

        Console.WriteLine("Press the Enter key to exit the program at any time... ");

        // If the timer is declared in a long-running method, use KeepAlive to prevent garbage collection 
        // from occurring before the method ends.  

    private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
        Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);

// This example displays output like the following:  
//       Press the Enter key to exit the program at any time...  
//       The Elapsed event was raised at 5/20/2015 8:48:58 PM  
//       The Elapsed event was raised at 5/20/2015 8:49:00 PM  
//       The Elapsed event was raised at 5/20/2015 8:49:02 PM  
//       The Elapsed event was raised at 5/20/2015 8:49:04 PM  
//       The Elapsed event was raised at 5/20/2015 8:49:06 PM 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft