C# 计时器

一、Stopwatch 主要用于测试代码段使用了多少时间

  使用方法:

      Stopwatch sw=new Stopwatch();

      sw.Start();

      ...

      sw.Stop();

      Console.WriteLine(sw.ElapsedMilliseconds);

二、System.Timers.Timer 主要用于按时间间隔循环执行代码

  使用方法:

      System.Timers.Timer timer=new System.Timers.Timer(100);

      timer.Elapsed+=new ElapsedEventHandler(TickTimer);

      timer.Start();

      private void TickTimer(object sender, ElapsedEventArgs e){}  //必须是事件

原文地址:https://www.cnblogs.com/alsofly/p/3375118.html