码迷,mamicode.com
首页 > 其他好文 > 详细

定时器Timer

时间:2014-12-17 17:54:17      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   io   color   sp   on   div   art   

定时器类:Timer

构造函数:Timer(TimerCallback callback, object state, uint dueTime, uint period)

callback:中断处理函数

state:中断处理函数的传入参数

dueTime:定时器开启之前的等待时间

period:定时器中断周期

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace theTimer
{
    class Program
    {
        int TimersCalled = 0;

        //#########################################################################
        //主函数
        //#########################################################################
        static void Main(string[] args)
        {
            Program p = new Program();

            Timer myTimer = new Timer(p.Display, "定时器传入参数(可以为null)", 200, 1000);//等待200毫秒后第一次调用,每1000毫秒重复1次
            Console.WriteLine("Timer start");

            Console.ReadLine();
        }

        //#########################################################################
        //回调函数
        //#########################################################################
        void Display(object state)
        {
            Console.WriteLine("{0}, 定时器第{1}次中断", (string)state, ++TimersCalled);
        }
    }
}

定时器Timer

标签:style   blog   ar   io   color   sp   on   div   art   

原文地址:http://www.cnblogs.com/xieqianli/p/4169681.html

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