:
This message was edited by stephl at 2006-6-6 1:49:1
: : i have used Sleep(n) in my code but am finding that is very inaccurate with errors upto 40 millisec. I need to replace this by a timer in some way by using a while loop or something. can anyone help me out by giving some simple code i can read ot understand how to use timers.any help would be great..
: :
: I do not know what precision you need, anyway you have to keep in mind that if you are working with a multitask system (like Windows), it is not so easy to wait for a very short time precisely. I have never tried this on a Windows OS and have no idea whether an error of 40ms is important or not.
: I do not think using WM_TIMER messages would be more accurate because the delivery of window messages takes time and I read that the programmer should not expect the timer to be very accurate.
:
: Steph
The WM_TIMER message is sent with the lowest priority possible. It is very inaccurate.
Look at the performance api's (QueryPerformanceCounter and QueryPerformanceFrequence for example). They may help you.
You must also give your thread high priority, to prevent Windows as much as possible from interrupting your process. But that slows other processes down.
Another option may be to use the Pentium's RDTSC instruction, which allows for clock-tick accuracy.
Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl