📜  c# timer - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:51.404000             🧑  作者: Mango

代码示例2
public static void Main()
{
    System.Timers.Timer aTimer = new System.Timers.Timer();
    aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    aTimer.Interval = 5000;
    aTimer.Enabled = true;

      // Handle close
    Console.WriteLine("Press \'q\' to quit the sample.");
    while(Console.Read() != 'q');
}

/// 
/// Specify what you want to happen when the Elapsed event is raised.
/// 
/// 
 private static void OnTimedEvent(object source, ElapsedEventArgs e)
 {
     Console.WriteLine("Hello World!");
 }