我有运行多个线程的应用程序。每个线程应该有检查的东西在该线程的范围内的计时器。我的问题是:哪一个定时器我应该使用的,什么是两者之间的区别
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 both.
本文提供了一个很好的比较,应该包含您所需要的信息:Comparing定时器类的.NET Framework类库中的:
This article provides an excellent comparison and should contain the information you need: Comparing the Timer Classes in the .NET Framework Class Library:
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)