在主线程中非阻塞的方式延时一段时间,仅适用于 Windows 平台:
procedure MsgWait(ADelay:Integer;ABreakOnAppQuit:Boolean);
var
AHandle:THandle;
T:Cardinal;
begin
while ADelay>0 do
begin
T:=GetTickCount;
if MsgWaitForMultipleObjects(0,AHandle,false,ADelay,QS_ALLINPUT)=WAIT_OBJECT_0 then
begin
Application.ProcessMessages;
if Application.Terminated and ABreakOnAppQuit then
Break;
end;
Dec(ADelay,GetTickCount-T);
end;
end;
