About the Timer class in C #, there are three timer classes in C #.

Source: Internet
Author: User
Tags net thread

· For the Timer class in C #, there are three timer classes in C #.
1. defined 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 used in winform. It is implemented through the windows message mechanism. Similar to the timer control in VB or Delphi, it is implemented using the API settimer internally. Its main disadvantage is that the timing is not accurate, and there must be a message loop, console application (console applicationProgram) Cannot be used.

System. Timers. timer and system. Threading. timer are very similar. They are implemented through the. NET thread pool. They are lightweight and time-precise, and have no special requirements on applications and messages. System. Timers. timer can also be used in winform to completely replace the above Timer control. Their disadvantage is that they do not support direct drag and drop and require manual encoding.

 

Example:
Use the system. Timers. Timer class
System. Timers. Timer T = new system. Timers. Timer (10000); // instantiate the Timer class and set the interval to 10000 milliseconds;
T. elapsed = new system. Timers. elapsedeventhandler (theout); // execute the event at the time of arrival;
T. autoreset = true; // set whether to execute once (false) or always execute (true );
T. Enabled = true; // whether to execute the system. Timers. Timer. elapsed event;Software Development Network

Public void theout (Object source, system. Timers. elapsedeventargs E)
{
MessageBox. Show ("OK! ");
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.