每隔5秒输出一个“Hello World!”,按q可以跳出程序。
static void Main(string[] args)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 5 seconds.
aTimer.Interval=5000;
aTimer.Enabled=true;
Console.WriteLine("Press /'q/' to quit the sample.");
Console.WriteLine("Hello World!");
while(Console.Read()!='q');
}
public static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Hello World!");
}