Several latency programs in VB

Source: Internet
Author: User
Tags sleep function
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 Function

The 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.