简体   繁体   English

Windows.Forms.Timer或System.Threading.Timer

[英]Windows.Forms.Timer OR System.Threading.Timer

I have an application that runs many threads. 我有一个运行许多线程的应用程序。 Each thread should have a timer that checks for something in that thread's scope. 每个线程都应该有一个计时器来检查该线程范围内的某些内容。 My question is: Which timer I should use and what is the difference between them? 我的问题是:我应该使用哪个计时器,它们之间有什么区别?

This article provides an excellent comparison and should contain the information you need: Comparing the Timer Classes in the .NET Framework Class Library : 本文提供了一个很好的比较,应该包含您需要的信息: 比较.NET Framework类库中的Timer类

Windows.Forms  System.Timers         System.Threading 
Timer event runs on what thread?    UI thread      UI or worker thread   Worker thread 
Instances are thread safe?          No             Yes                   No 
Familiar/intuitive object model?    Yes            Yes                   No 
Requires Windows Forms?             Yes            No                    No 
Metronome-quality beat?             No             Yes*                  Yes* 
Timer event supports state object?  No             No                    Yes 
Initial timer event schedulable?    No             No                    Yes 
Class supports inheritance?         Yes            Yes                   No

* Depending on the availability of system resources (for example, worker threads) *取决于系统资源的可用性(例如,工作线程)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM