System.Timers.Timer的VS System.Threading.Timer [英] System.Timers.Timer vs System.Threading.Timer
问题描述
我已经检查出一些可能的定时器最近,和 Threading.Timer 和 Timers.Timer 是那些看起来要紧的我(因为他们支持的线程池)。
I have been checking out some of the possible timers lately, and the Threading.Timer and 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.
这将是最好的吗?
推荐答案
本文提供了一个相当COM prehensive说明:
This article offers a fairly comprehensive explanation:
<一href="https://web.archive.org/web/20150329101415/https://msdn.microsoft.com/en-us/magazine/cc164015.aspx">Comparing定时器类在.NET Framework类库 - 也可<一个href="http://download.microsoft.com/download/3/a/7/3a7fa450-1f33-41f7-9e6d-3aa95b5a6aea/MSDNMagazineFebruary2004en-us.chm">as .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的VS System.Threading.Timer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!