System.Timers.Timer vs System.Threading.Timer

Viewed 333617

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?

9 Answers

As other mentioned the link to MS Docs, one major difference between System.Timers.Timer and System.Threading.Timer is that System.Threading.Timer executes a single callback method defined once while the System.Timers.Timer reacts on events, so supports multiple subscribers which can be also removed.

As also mentioned above, the System.Timers.Timer is using a System.Threading.Timer internally, with e.g. the Enable=false disposing the internal timer, and re creates it on Enable=true / Start(): https://source.dot.net/#System.ComponentModel.TypeConverter/System/Timers/Timer.cs

Related