I recently wrote something that uses the latency function. Sort it out:
Code 1 private declare sub sleep lib "Kernel32" (byval dwmilliseconds as long) Code 2 Private declare function timegettime lib "winmm. DLL "() as longfunction delaytime (milliseconds as integer) dim savetime as double savetime = timegettime 'write down the start time while timegettime <savetime + milliseconds 'loop waiting for doevents' to transfer control, so that the operating system can handle other events. Wendend Function Code 3 private declare sub sleep lib "Kernel32" (byval dwmilliseconds as long) Private declare function timegettime lib "winmm. DLL "() as longfunction delaytime (milliseconds as integer) 'Modified latency program dim savetime as double savetime = timegettime' write down the start time while timegettime <savetime + milliseconds 'Wait for sleep (30) 'and add this sentence, the latency of this function does not occupy CPU resources, nor is it similar to the sleep function. After the function is called, the program does not respond. Doevents 'transfer control so that the operating system can handle other events. Wendend FunctionThe above three codes can be delayed. The disadvantage of code 1 is that after the delay is long, the program does not respond during the delay process. The disadvantage of Code 2 is that the program responds when the delay occurs, in the process of latency, the CPU usage is close to 100%. In Code 3, the first two codes are used. In the process of latency, the program also responds and the CPU usage is small.