两秒打印一次时间
代码:
using System;
using System.Timers;
public class Program
{
private static System.Timers.Timer timer1;
static void Main()
{
timer1= new System.Timers.Timer(2000);
timer1.Elapsed += OnTImeEvent;
timer1.AutoReset = true;
timer1.Enabled = true;
Console.WriteLine("enter退出");
Console.ReadKey();
timer1.Stop();
timer1.Dispose();
}
private static void OnTImeEvent(Object source, ElapsedEventArgs e)
{
Console.WriteLine("时间到了{0:HH:mm:ss.fff}", e.SignalTime);
}
}
输出结果:
enter退出
时间到了16:50:13.482
时间到了16:50:15.484
时间到了16:50:17.481
标签:39,定时器,Console,16,C#,System,static,timer1,Timers
From: https://blog.csdn.net/S13461120713/article/details/144967313