C# Timer Timer(Double)
Description
Timer Timer(Double)
Initializes a new instance of the
Timer class, and sets the Interval property to the specified number of milliseconds.
Syntax
Timer.Timer(Double)
has the following syntax.
public Timer(
double interval
)
Parameters
Timer.Timer(Double)
has the following parameters.
interval
- The time, in milliseconds, between events. The value must be greater than zero and less than or equal to Int32.MaxValue.
Example
using System;/*from www . ja v a 2s .co m*/
using System.Timers;
public class Timer2
{
private static System.Timers.Timer aTimer;
public static void Main()
{
aTimer = new System.Timers.Timer(10000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.AutoReset = false;
aTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();
//GC.KeepAlive(aTimer);
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}
}
The code above generates the following result.