挂起不占CPU
sleep
不挂起占cpu
procedure Delay(msecs:integer);
var
FirstTickCount:longint;
begin
FirstTickCount:=GetTickCount;
repeat
ApplicationProcessMessages;
until ((GetTickCountFirstTickCount) >= Longint(msecs));
end;
定时器
procedure timerfun(handle:Thandle;msg:word;identer:word;dwtime:longword);stdcall;
begin
showmessage(到点了);
killtimer(handleidenter);//关闭定时器
end;
//其中的identer是定时器的句柄
procedure TFormButtonClick(Sender: TObject);
var
identer:integer;
begin
identer:=settimer(@timerfun);
if identer= then exit; //定时器没有创建成功
end;
不占CPU不挂起
function TFormHaveSigned(MaxWaitTime: Cardinal): Boolean;
var I:Integer;
var WaitedTime:Cardinal;
begin
WaitedTime:=;
while (WaitedTime<MaxWaitTime) do
begin
SleepEx(False);
Inc(WaitedTime);
ApplicationProcessMessages ;
end
end;