I was thinking about how timers work, and there’s something I don’t fully understand.
A Timer uses an event that is called when the time elapses. This I assume is triggered by an OS event that controls the clock (or is controlled by the clock).
But I’m not sure what thread will catch that event..
Does a Timer object have a thread of its own ?
Or will the event be called in the thread which created the timer object ?
EDIT:
And is there a difference in that aspect between System.Timers.Timer and System.Windows.Forms.Timer ?
It depends on the
Timer. If you useSystem.Windows.Forms.Timer, the tick event will be handled in the UI thread. InSystem.Threading.TimerandSystem.Timers.Timerit defaults to a thread pool thread. However, in the latter case you can specify aSynchronizingObjectwhich can be used to marshal the handler to an appropriate thread.