欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# System.Timers Demo

程序员文章站 2022-06-10 19:33:21
static void Main(string[] args) { SystemTimersDemo(); Console.ReadLine(); } static void SystemTimersDemo() { System.Timers.Timer timer = new System.Ti... ......
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")}");
        }