zoukankan      html  css  js  c++  java
  • C# Timer自带定时器

    官方文档

    https://msdn.microsoft.com/zh-cn/library/system.timers.timer.aspx

    using System;
    using System.Timers;
    
    public class Example
    {
       private static System.Timers.Timer aTimer;
    
       public static void Main()
       {
          SetTimer();
    
          Console.WriteLine("
    Press the Enter key to exit the application...
    ");
          Console.WriteLine("The application started at {0:HH:mm:ss.fff}", DateTime.Now);
          Console.ReadLine();
          aTimer.Stop();
          aTimer.Dispose();
    
          Console.WriteLine("Terminating the application...");
       }
    
       private static void SetTimer()
       {
            // Create a timer with a two second interval.
            aTimer = new System.Timers.Timer(2000);
            // Hook up the Elapsed event for the timer. 
            aTimer.Elapsed += OnTimedEvent;
            aTimer.AutoReset = true;
            aTimer.Enabled = true;
        }
    
        private static void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}",
                              e.SignalTime);
        }
    }
    // The example displays output like the following:
    //       Press the Enter key to exit the application...
    //
    //       The application started at 09:40:29.068
    //       The Elapsed event was raised at 09:40:31.084
    //       The Elapsed event was raised at 09:40:33.100
    //       The Elapsed event was raised at 09:40:35.100
    //       The Elapsed event was raised at 09:40:37.116
    //       The Elapsed event was raised at 09:40:39.116
    //       The Elapsed event was raised at 09:40:41.117
    //       The Elapsed event was raised at 09:40:43.132
    //       The Elapsed event was raised at 09:40:45.133
    //       The Elapsed event was raised at 09:40:47.148
    //
    //       Terminating the application...
    
  • 相关阅读:
    杜教筛
    虚树
    带修莫队
    线性基
    区间修改区间求和cdq分治
    矩阵快速幂求斐波那契数列
    点分治成品
    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)
    线性筛
    矩阵快速幂
  • 原文地址:https://www.cnblogs.com/danlis/p/5319074.html
Copyright © 2011-2022 走看看