Search code examples
.netclrsscli

Does CLR internally spawns a thread to respond to timer events?


Hans and I had small discussion recently about the subject and I'm curious how it is really implemented.

See initial talking in the comments here: Are c# timers naturally multithreaded?


Solution

  • Well, I did some investigations... Details are in my blog post

    To be short, just summary from there:

    • As for SSCLI20 Hans was totally right. There’s really separate thread for handing APCs and queued timers. Thanks for your insistence, btw. I received a chance to dig something interesting :)
    • On newer systems it still could be implemented without additional threads. I was just mistakenly assuming it was already there when CLR 2.0 was written. For details see CreateThreadpoolTimer, SetThreadpoolTimer and CloseThreadpoolTimer.