static void Main(string[] args) { SystemThreadingTimerDemo(); Console.ReadLine(); } static void SystemThreadingTimerDemo() { System.Threading.Timer timer = new Timer(TimerCB2, 0, 0, 10000); } private static void TimerCB2(object state) { NumIncrement(); } static void SystemTimersTimerDemo() { System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = 10000; timer.Elapsed += TimerElapsed; timer.Start(); } private static void TimerElapsed(object sender, System.Timers.ElapsedEventArgs e) { NumIncrement(); } public static void NumIncrement() { Num = 0; DateTime dt = DateTime.Now; DateTime endDt = dt.AddSeconds(10); while (DateTime.Now < endDt) { Num++; Console.WriteLine($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")},Num={Num}"); Thread.Sleep(1000); } }