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.
Which would be the best?
System. Threading. Timer, which executes a single callback method on a thread pool thread at regular intervals. The callback method is defined when the timer is instantiated and cannot be changed.
Yes, they run in a different thread.
Timer is not thread-safe.
Remarks. The Timer component is a server-based timer that raises an Elapsed event in your application after the number of milliseconds in the Interval property has elapsed. You can configure the Timer object to raise the event just once or repeatedly using the AutoReset property.
This article offers a fairly comprehensive explanation:
"Comparing the Timer Classes in the .NET Framework Class Library" - also available as a .chm file
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With