如何实现延时? (100分)

  • 主题发起人 主题发起人 caining
  • 开始时间 开始时间
C

caining

Unregistered / Unconfirmed
GUEST, unregistred user!
[red][/red][:)]在程序中如何实现延时例如10秒,再接着执行下面的程序?
 
sleep(10000);
 
同意楼上的
SLEEP()函数的单位是豪秒
 
timer 空间可以
如果
对性能要求不高的话
 
最常用:Sleep
李维爱用GetTickTime
 
GetTickTime 是得到开机时到当前的时间。延时一般用Sleep()就行了
 
sleep(毫秒)
1秒=1000毫秒
 
Sleep(1000*10)啊,傻瓜.
 
主要看用途
不精确:sleep
比较精确:timer
精确:GetTickTime
 
sleep直接将当前进程挂起,一点都不销耗系统资源,推荐
 
推荐 用GetTickTime,我常用!呵呵
 
application.processmessages
SLEEP(10000)
 
用sleep(XXXX);比较方便。注意有时加上application.progressmessage;
 
就用sleep吧
 
我也想知有没更好的方法,下面的函数 CPU 占用太利害了。

procedure delay(MSEL : integer);
var
FirstTickCount: real;
begin
FirstTickCount := GetTickCount;
Repeat
Application.ProcessMessages;
until (GetTickCount - FirstTickCount) >= Msel;
end;
 
我原来也是用的delay这种方式,但Cpu占用资源100%,最后改用Timer或Sleep
 
---->我也想知有没更好的方法,下面的函数 CPU 占用太利害了。
delay 1ms没什么意义,delay10个ms试试,
修改如下,看不出占用CPU:
procedure delay(MSEL : integer);
var
FirstTickCount: real;
begin
FirstTickCount := GetTickCount;
Repeat
Application.ProcessMessages; sleep(10);
until (GetTickCount - FirstTickCount) >= Msel;
end;
 
同意Pc 狂迷。
 
引用苦虫兄:
主要看用途
不精确:sleep
比较精确:timer
精确:GetTickTime
 
后退
顶部