c# - Windows.Forms.Timer 或 System.Threading.Timer

标签 c# .net timer

我有一个运行许多线程的应用程序。每个线程都应该有一个计时器来检查该线程范围内的某些内容。我的问题是:我应该使用哪个计时器,它们之间有什么区别?

最佳答案

本文提供了一个很好的比较,应该包含您需要的信息: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

* 取决于系统资源的可用性(例如,工作线程)

关于c# - Windows.Forms.Timer 或 System.Threading.Timer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4532850/

相关文章:

c# - 是否有与 Android 选择器等效的 Windows(电话)?

.net - 为什么 Random() 不是随机的?

c# - 如何使用 RefIdStr 和 RavenDB 扩展 ServiceStack UserAuth

c# - 绑定(bind) ObservableCollection 对象麻烦

c# - DDD - 实体状态转换

ios - 如何在 onReceive 定时器关闭 SwiftUI iOS 中导航另一个 View

c# - CPU使用率在执行过程中变得非常高

c# - Java 中 C# 中的 Timer 等价物?

c# - 为什么这个 LINQ 会抛出 NullReferenceException?

.net - 适用于 Visual Studio 2008 的 Crystal Reports 合并模块