计时器的使用

时间:2022-08-31 20:33:07

 1 // Summary:
 2 //     A timer that is integrated into the System.Windows.Threading.Dispatcher queue
 3 //     which is processed at a specified interval of time and at a specified priority.
 4 DispatcherTimer timer = new DispatcherTimer();
 5 // Summary:
 6 //     Occurs when the timer interval has elapsed.
 7 timer.Tick += (sender, e) => { System.Console.WriteLine("SubmarineX"); };
 8 // Summary:
 9 //     Gets or sets the period of time between timer ticks.
10 //
11 // Returns:
12 //     The period of time between ticks. The default is 00:00:00.
13 //
14 // Exceptions:
15 //   System.ArgumentOutOfRangeException:
16 //     interval is less than 0 or greater than System.Int32.MaxValue milliseconds.
17 timer.Interval = new System.TimeSpan(0, 0, 1);
18 // Summary:
19 //     Starts the System.Windows.Threading.DispatcherTimer.
20 timer.Start();