Search code examples
c#multithreadingtimer

Does a System.Timers.Timer elapse on a separate thread?


Does a System.Timers.Timer elapse on a separate thread than the thread that created it?

Let's say I have a class with a timer that fires every 5 seconds. When the timer fires, in the elapsed method, some object is modified. Let's say it takes a long time to modify this object, like 10 seconds. Is it possible that I will run into thread collisions in this scenario?


Solution

  • For System.Timers.Timer:

    See Brian Gideon's answer below

    For System.Threading.Timer:

    MSDN Documentation on Timers states:

    The System.Threading.Timer class makes callbacks on a ThreadPool thread and does not use the event model at all.

    So indeed the timer elapses on a different thread.