Timing
• 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.
Cases:
Using the System.Timers.Timer class
System.Timers.Timer t = new System.Timers.Timer (10000);//Instantiate Timer class, set interval time to 10000 milliseconds;
t.elapsed + = new System.Timers.ElapsedEventHandler (theout);//Time of arrival to execute event;
T.autoreset = true;//Whether the setting is executed once (false) or always (true);
t.enabled = true;//Whether the System.Timers.Timer.Elapsed event is executed;
public void Theout (object source, System.Timers.ElapsedEventArgs e)
{
MessageBox.Show ("ok!");
}