Reputation: 11190
If I start a System.Threading.Timer, does it consume a ThreadPool thread while waiting (bad), or only when the timer is executing the TimerCallback?
Upvotes: 1
Views: 213
Reputation: 941327
Yes. And no. It depends on your .NET framework version. Traditionally no, it consumed an entire thread. Started by the CLR to handle all active timers.
Not so on more recent versions, like my 4.5.1 running on Windows 8.1. It has switched to using CreateTimerQueueTimer to get that job done. That's pooled by the operating system.
Get insight by enabling unmanaged debugging and setting a breakpoint on the timer's callback. Look at the call stack.
Upvotes: 3
Reputation: 437336
Only when the callback is being executed. Note that if the duration of the callback is longer than the timer interval multiple thread pool threads will end up executing the callback concurrently.
Upvotes: 2