C# System.Timers Demo

static void Main(string[] args)
        {
            SystemTimersDemo();
            Console.ReadLine();
        }

        static void SystemTimersDemo()
        {
            System.Timers.Timer timer = new System.Timers.Timer(1000);
            timer.Elapsed += Timer_Elapsed;
            timer.AutoReset = true;
            timer.Enabled = true;
        }

        private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Console.WriteLine($"The Elapsed event was raised at {e.SignalTime.ToString("yyyyMMddHHmmssffff")}");
        }

 

上一篇:C#-Forms.Timer、Timers.Timer、Threading.Timer的比较和使用


下一篇:过滤器的实现原理