System.Timers.Timer 与 System.Threading.Timer [英] System.Timers.Timer vs System.Threading.Timer
问题描述
我最近一直在检查一些可能的计时器,System.Threading.Timer
和 System.Timers.Timer
对我来说是必要的(因为它们支持线程池).
I have been checking out some of the possible timers lately, and System.Threading.Timer
and System.Timers.Timer
are the ones that look needful to me (since they support thread pooling).
我正在制作一个游戏,我计划使用所有类型的事件,具有不同的时间间隔等.
I am making a game, and I plan on using all types of events, with different intervals, etc.
哪个最好?
推荐答案
这篇文章提供了一个相当全面的解释:
This article offers a fairly comprehensive explanation:
"比较.NET Framework 类库中的计时器类" - 也可用 作为 .chm 文件
具体的区别似乎是 System.Timers.Timer
面向多线程应用程序,因此通过其 SynchronizationObject
属性是线程安全的,而 System.Threading.Timer
讽刺的是不是线程安全的开箱即用.
The specific difference appears to be that System.Timers.Timer
is geared towards multithreaded applications and is therefore thread-safe via its SynchronizationObject
property, whereas System.Threading.Timer
is ironically not thread-safe out-of-the-box.
我认为两者之间没有区别,因为它与您的间隔可以有多小有关.
I don't believe that there is a difference between the two as it pertains to how small your intervals can be.
这篇关于System.Timers.Timer 与 System.Threading.Timer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!