During windows programming, sleep () is often used as a Windows standard API function to implement latency wait. But the biggest problem with this thread is that the entire thread is suspended after sleep is called. And cannot process Windows messages.
Tfxsleep solves this problem. When the system gets stuck and waits for timeout, it can process Windows messages.
// Latency? Time, during which Windows events can be processed
Void tfxsleep (ulong ulmilliseconds)
{
DWORD lfirst = gettickcount ();
MSG;
Do
{
If (peekmessage (& MSG, null, 0, 0, pm_remove ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Sleep (1 );
} While (gettickcount ()-lfirst <ulmilliseconds );
}
A friend (Loki. W. Zuo) once read the Post and commented:
Another way is to use the lock mechanism (critical resource objects can be used in Windows), lock yourself, and then release it by others.
Advantages: actively request process/thread switching.