Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Timers.Timer vs System.Threading.Timer

Tags:

.net

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.

Which would be the best?

like image 709
TheAJ Avatar asked Sep 13 '09 03:09

TheAJ


People also ask

What is System threading timer?

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.

Does System timers timer run in a separate thread?

Yes, they run in a different thread.

Is System threading timer thread safe?

Timer is not thread-safe.

How does System timer work?

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.


1 Answers

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.

like image 148
David Andres Avatar answered Oct 05 '22 09:10

David Andres