Do .NET Timers Run Asynchronously?

.net, c#, multithreading, timer

Solution

What kind of timer are you using?

- `System.Windows.Forms.Timer` will execute in the UI thread

- `System.Timers.Timer` executes in a thread-pool thread unless you specify a `SynchronizingObject`

- `System.Threading.Timer` executes its callback in a thread-pool thread

In all cases, the timer itself will be asynchronous - it won't "take up" a thread until it fires.

Problem

I have a messaging aspect of my application using Jabber-net (an XMPP library.) What I would like to do, if for some reason the connection to the Server is ended, is keep trying to connect every minute or so. If I start a Timer to wait for a period of time before the next attempt, does that timer run asynchronously and the resulting Tick event join the main thread, or would I need to start my own thread and start the timer from within there?

Original source