4 ms·
For Windows, you can use CreateWaitableTimer to create a timer that doesn't need a window: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synch
by tom_ 2y ago
For Windows, you can use CreateWaitableTimer to create a timer that doesn't need a window: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createwaitabletimerw https://learn.microsoft.com/en-us/windows/win32/api/synchapi...
Wait for it to time out using one of the WaitFor family of functions.
- leeter 2y agoAlternatively there is everybody's favorite CreateThreadpoolTimer https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-createthreadpooltimer https://learn.microsoft.com/en-us/windows/win32/api/threadpo... now that the threadpool is active on any Win32 process by default AFAIK. But for something you don't mind blocking the above is often easier to use.
- tom_ 2y agoWhew, so we've got CreateWaitableTimer, CreateTimerQueueTimer from another comment, and now CreateThreadpoolTimer as well. But that's not all - we already had WM_TIMER from the article. TFA says POSIX has one type of timer, and it sucks. Windows has 4 types... but how many of them suck? I've used CreateWaitableTimer, and it was alright. I do know WM_TIMER sucks, but I've never used CreateTimerQueueTimer or CreateThreadpoolTimer. So, worst case is a draw. I'd like to see Windows winning here though.