一个延迟函数,将替代sleep函数!

在Delphi使用中经常会使用到sleep来进行延迟,短时间还好,时间长的话那sleep会卡死程序,我在网络上找到了个函数,该函数可以直接替换Sleep来使用,我感觉还不错,就收集了下。

procedure Delay(msecs: Integer);
var
Tick: DWord;
Event: THandle;
begin
Event :
= CreateEvent(nil, False, False, nil);
try
Tick :
= GetTickCount + DWord(msecs);
while (msecs > 0) and (MsgWaitForMultipleObjects(1, Event, False, msecs,
QS_ALLINPUT)
<> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
msecs :
= Tick - GetTickCount;
end;
finally
CloseHandle(Event);
end;
end;

你可能感兴趣的:(sleep)