w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I execute 10ms CPU time operation exactly 30ms interval in Windows?

I like CreateWaitableTimer for this. You can wait for it on a dedicated worker thread using WaitForSingleObject, a shared worker using WaitForMultipleObjects, or even on your UI thread by writing your main message loop to use MsgWaitForMultipleObjects.

Your 5ms precision should be achievable unless your system is badly overloaded. Thread priorities can help, but I/O is rarely prioritized, so if you do a blocking read of a file, you can be queued behind read requests from the same disk from much lower priority threads. Try to load any data in advance or use overlapped requests and deal with the condition that the request hasn't completed yet when your timer interval expires.

And I definitely would suggest using timeBeginPeriod to make all system timers more precise.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.