For the delay of four methods Delphi

 1, suspended, does not occupy the CPU
SLEEP
2, not suspended, accounting CPU
Procedure Delay (for msecs: Integer);
var
FirstTickCount: LongInt;
the begin
FirstTickCount: = the GetTickCount;
REPEAT
Application.ProcessMessages by;
an until ((the GetTickCount-FirstTickCount)> = LongInt (for msecs));
End;
. 3, the timer
Procedure timerfun (handle: THandle; MSG: Word; identer: Word; dwTime: longword is); _stdcall;
the begin
ShowMessage ( 'the point');
KillTimer (handle, identer) ; // Off timer
end;

// timer which is identer handle
Procedure TForm1.Button1Click (Sender: TObject);
var
identer: Integer;
the begin
   identer: = SetTimer (0,0,2000, @ timerfun);
   IF = 0 identer the then Exit; // timer has not successfully created.
End;
. 4, does not occupy the CPU does not suspend
function TForm1.HaveSigned (MaxWaitTime: Cardinal): Boolean;
var the I: Integer;
var WaitedTime: Cardinal;
the begin
          WaitedTime: = 0;
          the while (WaitedTime
          the begin
                  SleepEx (100, False);
                  Inc is an (WaitedTime, 100);
                  Application.ProcessMessages by;
          End
End;

Guess you like

Origin www.cnblogs.com/jijm123/p/11747304.html