我是靠谱客的博主 温柔服饰,这篇文章主要介绍C# System.Timers.Timer用法,现在分享给大家,希望可以做个参考。

//简单的demo使用Timer计时器
class Program
    {

        static void Main(string[] args)
        {
            Timer timer = new Timer();
            timer.Enabled = true;//设置是否执行Elapsed事件
            timer.Elapsed += new ElapsedEventHandler(printa);//绑定Elapsed事件
            timer.Interval = 3000;//设置时间间隔
            Console.ReadKey();
        }

        public static void printa(object sender, ElapsedEventArgs e)
        {

            Console.WriteLine(DateTime.Now.ToString()+"执行Timer");
        }
    }

运行结果每三秒执行一次,运行结果如下图

这里写图片描述

最后

以上就是温柔服饰最近收集整理的关于C# System.Timers.Timer用法的全部内容,更多相关C#内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部