日期:2014-05-18 浏览次数:21104 次
    class TimerExampleState 
    {
      public int counter = 0;
      public Timer tmr;
    }
    class App 
    {
      public static void Main()
      {
          TimerExampleState s = new TimerExampleState();
          //创建代理对象TimerCallback,该代理将被定时调用
          TimerCallback timerDelegate = new TimerCallback(CheckStatus);
            //创建一个时间间隔为1s的定时器
            Timer timer = new Timer(timerDelegate, s,1000, 1000);
            s.tmr = timer;
            //主线程停下来等待Timer对象的终止
            while(s.tmr != null)
            Thread.Sleep(0);
            Console.WriteLine("Timer example done.");
            Console.ReadLine();
      }