What are the programming methods for delayed execution?
What are the programming methods of delay function
1. Call the API SetTimer() function of the system timer to implement delay, and you need to include the header file
2. To achieve delay by cyclically calling the clock() function to read the program running time, the header file needs to be included
3. By calling the Sleep() function, you need to include the header file
The delay accuracy that the above functions can achieve is about 10ms
void delay(double second)
{
LARGE_INTEGER litmp;
LONGLONG QPart1, QPart2;
double dfMinus, dfFreq, dfTim;
QueryPerformanceFrequency(&litmp);
dfFreq = (double)litmp.QuadPart; // Get the clock frequency of the counter
QueryPerformanceCounter(&litmp);
QPart1 = litmp.QuadPart; // Get the initial value
do
{
QueryPerformanceCounter(&litmp);
QPart2 = litmp.QuadPart; //Get the abort value
dfMinus = (double)(QPart2 - QPart1);
dfTim = dfMinus / dfFreq; // Get the corresponding time value in seconds
}
while(dfTim
}
How to postpone the execution of a function in HTML5
1.[self performSelector:@selector (function name) withObject:nil afterDelay:5.0f]
Condition: In the main thread of uiviewController
2.[NSTimerscheduledTimerWithTimeInterval:5.0f target:self selector:@selector (function name) userInfo:nil repeats:NO];
In the specific function, execute the code, and after the execution is completed, call the NSTimer invalidate method to destroy the timer
3.[NSThread sleepForTimeInterval:5.0f];
[Method to delay execution];
Conditions: Main thread or sub-thread can be used
How to delay the execution of specified commands in bat
First of all, bat delay refers to executing a command and delaying it for a period of time before proceeding with the next command. Under cmd or in batch processing, the following four methods are often used for time delay:
1. Use the ping command to delay.
Example 1:
@echo off
echo before delay: %time%
ping /n 3 127.0.0.1 >nul
echo after delay: %time%
pause
2. Use the for command to delay.
Example 2:
@echo off
echo before delay: %time%
for /l %%i in (1,1,5000) do echo %%i>nul
echo after delay: %time%
pause
3. Use vbs delay function, with millisecond accuracy and error within 1000 milliseconds.
Example 3:
@echo off
echo %time%
call :delay 5000
echo %time%
pause
exit
:delay
echo WScript.Sleep %1>delay.vbs
CScript //B delay.vbs
del delay.vbs
goto :eof
4. Only use batch processing commands to achieve any time delay, with an accuracy of 10 milliseconds and an error of 50 milliseconds. Only batch processing commands can be used to achieve delay operations.
Example 4:
@echo off
set /p delay=Please enter the number of milliseconds to be delayed:
set TotalTime=0
set NowTime=%time%
:: Reading starting time, the time format is: 13:01:05.95
echo program start time: %NowTime%
:delay_continue
set /a minute1=1%NowTime:~3,2%-100
:: Read the starting time in minutes
set /a second1=1%NowTime:~-5,2%%NowTime:~-2%0-100000
:: Convert the starting time seconds to milliseconds
set NowTime=%time%
set /a minute2=1%NowTime:~3,2%-100
:: Read the minutes of the current time
set /a second2=1%NowTime:~-5,2%%NowTime:~-2%0-100000
:: Convert the seconds of the current time to milliseconds
set /a TotalTime =(%minute2%-%minute1% 60)%`*60000 %second2%-%second1%
if %TotalTime% lss �lay% goto delay_continue
echo program end time: %time%
echo set delay time: �lay% milliseconds
echo actual delay time: %TotalTime% milliseconds
pause
I hope the above methods can help you solve the problem satisfactorily!
The above is the detailed content of What are the programming methods for delayed execution?. For more information, please follow other related articles on the PHP Chinese website!

Data recovery is always a heated topic. To successfully restore data from your device, you should know how it stores data. You can learn the difference between RAID recovery and hard drive recovery from this php.cn post.

Do you run into Word text disappearing while typing? Some letters or even paragraphs might disappear from your document. What’s wrong with it? In this post from php.cn Website, we will take a closer look at the Word automatically deleting text issue

When you are trying to log into Overwatch 2, you may receive the LC-208 error message and it prevents your game from connecting to the game servers. This post from php.cn introduces how to fix the LC-208 Overwatch error.

Generally, you can quickly access and edit Google Drive files from File Explorer. However, sometimes you may encounter the issue of “Google Drive disappeared from File Explorer”. Here this post on php.cn tells you how to get Google Drive to show up i

Why is my computer on the welcome screen for so long? How to fix Windows 7 welcome screen slow? If you still run Windows 7 on your PC and meet this issue, you are in the right place and multiple solutions will be given here by php.cn.

Want to use the built-in password management tool – Credential Manager to manage your login credentials for web and apps? How can you open Credential Manager in Windows 11? In this post, php.cn collected multiple ways to access this utility, and let’

Microsft Defender Antivirus has a feature called Periodic scanning, which can be enabled when you have installed another antivirus product on a Windows 11/10 device. Now, this post from php.cn teaches you how to enable/disable Periodic scanning on Wi

Have you ever encountered the issue of “Excel hyperlinks not working”? Do you know how to deal with it? In this post from php.cn, you can get several feasible solutions to get rid of this problem. And you will know a professional data recovery tool t


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools