About the Timer class in C # There are 3 of timer classes in C #:
1. Definition in System.Windows.Forms
2. defined in the System.Threading.Timer class
3. defined in the System.Timers.Timer class
System.Windows.Forms.Timer is applied to WinForm, it is implemented through the Windows messaging mechanism, similar to the Timer control in VB or Delphi, the internal use of API SetTimer implementation. Its main disadvantage is that the timing is imprecise and that there must be a message loop that the console application (console application) cannot use.
System.Timers.Timer and System.Threading.Timer are very similar, they are implemented through the. NET Thread Pool, lightweight, timed accurately, with no special requirements for applications or messages.
System.Timers.Timer can also be applied to WinForm to completely replace the timer control above. Their disadvantage is that they do not support direct drag-and-drop and require manual coding.
This paper url:http://www.bianceng.cn/programming/csharp/201410/45596.htm
The following example illustrates the use of the System.Timers.Timer timer.
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Using System.Timers;
Using System.Runtime.InteropServices;
Using System.Threading;
namespace Timer001 {public partial class Form1:form {public Form1 () {
InitializeComponent ();
//Instantiate Timer class System.Timers.Timer Atimer = new System.Timers.Timer (); private void Button1_Click (object sender, EventArgs e) {this.
Settimerparam (); private void Test (object source, System.Timers.ElapsedEventArgs e) {Messa
Gebox.show (DateTime.Now.ToString ()); public void Settimerparam () {//Time to execute event atimer.elapsed + = new ElApsedeventhandler (test);
Atimer.interval = 1000; Atimer.autoreset = true;//performs false once, executes true//whether the System.Timers.Timer.Elapsed event is performed atimer.enabl
ed = true; }
}
}
The effect of the implementation is: the current time of the pop-up system per second, the following figure: