Delphi delay function is much better than sleep

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

From:

//Method: a delay function

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;

//Delayed function: two

procedure Delay(dwMilliseconds:DWORD);//Longint

var

iStart,iStop:DWORD;

begin

iStart :=   GetTickCount;

repeat

iStop  :=   GetTickCount;

Application.ProcessMessages;

until (iStop  -  iStart) >= dwMilliseconds;

end;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Fitzgerald at December 23, 2013 - 1:01 AM