码迷,mamicode.com
首页 > Windows程序 > 详细

C# --System.Timers.Timer 定时方法

时间:2015-05-22 11:16:46      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

注意Start()

注意要等Interval 时间间隔

        static void Main(string[] args)
        {
            System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类,设置时间间隔
            t.Interval = 0.5 * 60 * 1000;
            t.Elapsed += new System.Timers.ElapsedEventHandler(RunConvert);//到达时间的时候执行事件
            t.AutoReset = true;//设置是执行一次(false)还是一直执行(true)
            t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件
            t.Start();
            RunConvert(null,null);
            Console.ReadKey();
        }
        static void RunConvert(object source, System.Timers.ElapsedEventArgs e)
        {
            Console.WriteLine("定时");
        }

 

C# --System.Timers.Timer 定时方法

标签:

原文地址:http://www.cnblogs.com/bmbh/p/4521530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!