Scenario 2: Call a Function at a Timed Interval
Sometimes applications need to perform certain tasks at certain times. Windows offers a waitable timer kernel object (described in Chapter 9) that makes it easy to get a time-based notification. Many programmers create a waitable timer object for each time-based task that the application will perform, but this is unnecessary and wastes system resources. Instead, you can create a single waitable timer, set it to the next due time, and then reset the timer for the next time, and so on. However, the code to accomplish this is tricky to write. Fortunately, you can let the thread pool functions manage this for you.
To schedule a work item to be executed at a certain time, you first need to define a callback ...
Get Windows® via C/C++, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.