时间延迟的问题,谁写一个时候延迟的方法吗?不要占用cup的使用率。
各为大虾,我是这样写的,但是占用cpu的使用率太高。
procedure WairForTime(const second: integer);
var
starttime: TDateTime;
begin
starttime := now;
repeat
application.processmessages;
until now > starttime + second * (1 / 24 / 60 / 60);
end;请问各位大虾,有没有更好的办法呢。不要用sleep函数。急请各位多多帮忙。谢谢。
各为大虾,我是这样写的,但是占用cpu的使用率太高。
procedure WairForTime(const second: integer);
var
starttime: TDateTime;
begin
starttime := now;
repeat
application.processmessages;
until now > starttime + second * (1 / 24 / 60 / 60);
end;请问各位大虾,有没有更好的办法呢。不要用sleep函数。急请各位多多帮忙。谢谢。
改进版var
NumSec SmallInt;
StartTime: LongInt;
begin
StartTime := GetTickCount;//用Now的修改系统时间就没效了,这个就不会
repeat
Application.ProcessMessages;
Sleep(1);//能解决CPU100%的问题
until GetTickCount > StartTime + 毫秒;
end;