System.Windows.Forms.Timer, System.Timers.Timer, System.Threading.Timer differences and when to use

Source: Internet
Author: User

Differences and usages of System.Windows.Forms.Timer, System.Timers.Timer and System.Threading.Timer
http://space.itpub.net/12639172/viewspace-571197

Http://msdn.microsoft.com/en-us/magazine/cc164015.aspx

==================================================

When System.Windows.Forms.Timer executes, if you add a sleep to the middle of the process, the entire interface dies.

But the other two don't have the same situation, System.Timers.Timer, system.threading.timer!.

System.Timers.Timer, System.Threading.Timer These two peacetime use time did not find too big difference, timing accuracy are similar.

General my personal use, or use System.Threading.Timer more, with the method of programming more useful!

System.Windows.Forms.Timer is UI-based
System.Timers.Timer is service-based
System.Threading.Timer is thread-based

In addition to the timer can only be used for the interface, other things do not see the difference

System.Windows.Forms.Timer and WPF. The Timer is single-threaded for too long a time to affect the next trigger accuracy difference


System.Threading.Timer are multi-threaded, a single run time is too long to affect the next trigger

High accuracy

System.Threading.Timer is a simple light-weight timer that uses callback methods and is serviced by thread pool threads. It is not recommended for use with Windows forms because its callbacks do not take place on the user interface thread. System.Windows.Forms.Timer is a better choice for Windows forms. To get the server-based timer feature, consider using System.Timers.Timer, which can raise events and have additional functionality.

The 3 timers are mentioned in "CLR Via C #", but the author says System.Timers.Timer is a System.Threading.Timer, not recommended, but in my Web project Application_ I still use this instead of threading.timer in start, because when I use Threading.timer, I do not execute it once.

For the use of the timer in the B/s structure is more complex, generally we put the timer in the Application_OnStart, so that the global maintenance of a timer, you can regularly back up the database, regular maintenance users and other operations, and the method of writing static, so as not to be garbage collection. It is not recommended to use in the General ASPX page, because the server-side timer is not very meaningful to the user, you can use JS instead. And every request on this page could introduce a new timer, causing the system to crash. In addition, the timer is an ASP. IIS-related, so for important execution tasks, it is recommended to write a service or stand-alone program on the server to execute.

http://blog.itpub.net/12639172/viewspace-571197

System.Windows.Forms.Timer, System.Timers.Timer, System.Threading.Timer differences and when to use

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.