Timer类
Timer类可以按照规定时间间隔重复生成事件
构造函数有两个
参数为重复生成事件的时间间隔
public Timer(); public Timer(double interval)
示例:
1 class Program 2 { 3 static int count1 = 0; 4 static string displayString = 5 "This String will appear one letter at time."; 6 static void Main(string[] args) 7 { 8 Timer myTimer = new Timer(100); 9 myTimer.Elapsed += new ElapsedEventHandler(WriteChar); //Timer的内置事件 10 myTimer.Start();12 ReadKey(); 13 } 14 static void WriteChar(object source, ElapsedEventArgs e) 15 => Write(displayString[count1++ % displayString.Length]); 16 }