Timer Constructor (Double)

Initializes a new instance of the Timer class, and sets the Interval property to the specified number of milliseconds.

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

public Timer(
	double interval


Type: System.Double

The time, in milliseconds, between events. The value must be greater than zero and less than or equal to Int32.MaxValue.


The value of the interval parameter is less than or equal to zero, or greater than Int32.MaxValue.

This constructor sets the Interval property of the new timer instance, but does not enable the timer.

The following example creates a Timer whose Elapsed event fires after 1.5 seconds. Its event handler then displays "Hello World!" on the console.

using System;
using System.Timers;

public class Example
    private static Timer aTimer;

    public static void Main()
        // Create a timer with a 1.5 second interval. 
        double interval = 1500.0;
        aTimer = new System.Timers.Timer(interval);

        // Hook up the event handler for the Elapsed event.
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

        // Only raise the event the first time Interval elapses.
        aTimer.AutoReset = false;
        aTimer.Enabled = true;

        // Ensure the event fires before the exit message appears.
        System.Threading.Thread.Sleep((int) interval * 2);
        Console.WriteLine("Press the Enter key to exit the program.");

    // Handle the Elapsed event. 
    private static void OnTimedEvent(object source, ElapsedEventArgs e) 
        Console.WriteLine("Hello World!");
// This example displays the following output: 
//       Hello World! 
//       Press the Enter key to exit the program.

.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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft