Implementing Timers
It would be easy to use existing C# constructs, such as sleeping threads or for and while loops, to control the periodic collection of performance counter data. The primary problems with these methods are their synchronous nature. Furthermore, loops like for and while deliver a significant performance hit. A better solution for performing logic via specified intervals is the timer.
A timer can be set for a specified time interval, executing a callback routine whenever that interval elapses. The primary benefit of this approach is the asynchronous behavior of the timer, which delivers much better performance than the synchronous methods discussed earlier. Just set the timer interval, assign a callback routine to execute, and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access