Microsecond delay
As we know the system has WM_TIMER which gives about 50mS resolution, and Mutlimedia Timers which can do about 1mS, and if one require a simple delay of say 100microseconds with about 5% accuracy there is nothing available to do that.
Using the GetTickCount() it is possible to adjust a simple for() loop that contains _asm {NOP} and get a reasonable delay accuracy.
The attached code sample explains itself.
One improvement I would make next time I use this, is to save the initialization values to the registry, and avoid doing it every time the program starts.
The code has been tested on three systems ( dual pentuim Pro running at 233MHz ) ( Penitum P5 at 233MHz) and Toshiba Laptop running at 133MHz.
Project File 31K

Comments
Anyone can explain NdisMSleep(IN ULONG MicrosecondsToSleep)?
Posted by Legacy on 02/22/2004 12:00amOriginally posted by: Alex Yang
Has anyone used
VOID NdisMSleep(IN ULONG MicrosecondsToSleep) ?
I wonder if it is usable on most computers and how to use it. It's from NT DDK I don't have but I can find its header file in \CYGWIN\USR\INCLUDE\W32API\DDK though.
ReplyAnother Delay function...
Posted by Legacy on 05/22/2003 12:00amOriginally posted by: Alex
ReplyCount FrameRate precisely
Posted by Legacy on 04/04/2003 12:00amOriginally posted by: David Lai
Hi! Everybody,
I want to control my application output each frame I captured, and let them work like TV. I tried to use GetTickCount() and WM_TIMER, however it was too fast, is there any kind of solutions? Thank you!
ReplyBad usage of CPU resources, use API Call ::Sleep() or ::SleepEx() instead
Posted by Legacy on 01/13/2002 12:00amOriginally posted by: OReubens
Actually, using a for-loop to WAIT is a bad idea. The wait in this way has the CPU cycle around until the time is passed, it eats up valuable CPU cycles that other processes/threads might put to good use...
Calling the Windows API function Sleep() or SleepEx() will have a millisecond delay, and it will yield whatever CPU cycles to other threads during the wait.
Reply
bad results with multimedia timers
Posted by Legacy on 05/31/1999 12:00amOriginally posted by: Filipe Campos
Reply