将内容过程比较常用的内容段收藏起来,下边内容内容是关于C#中timer定时器的用法演示的内容,希望能对码农有一些用途。
using System;
using System.Timers;
class TestTimer
{
public static void Main ()
{
Timer timer = new Timer();
timer.Elapsed + = new ElapsedEventHandler(DisplayTimeEvent);
timer.Interval = 1000;
timer.Start();
timer.Enabled = true;
while (Console.Read ()! = 'q')
{
}
}
public static void DisplayTimeEvent (object source, ElapsedEventArgs e)
{
Console.Write({0}, DateTime.Now);
}
}
转载于:https://blog.51cto.com/14143192/2378834