Using waitable timer in Delphi



procedure Wait(lNumberOfSeconds : Longint);
const
_SECOND = 10000000;
var
lBusy : LongInt;
hTimer : LongInt;
liDueTime : LARGE_INTEGER;

begin
hTimer := CreateWaitableTimer(nil, True, 'WaitableTimer');
if hTimer = 0 then
Exit;
liDueTime.QuadPart := -10000000 * lNumberOfSeconds;
SetWaitableTimer(hTimer, TLargeInteger(liDueTime), 0, nil, nil, False);

repeat
lBusy := MsgWaitForMultipleObjects(1, hTimer, False,
INFINITE, QS_ALLINPUT);
Application.ProcessMessages;
Until lBusy = WAIT_OBJECT_0;

// Close the handles when you are done with them.
CloseHandle(hTimer);

End;
procedure TForm1.Button1Click(Sender: TObject);
begin
form1.Caption := 'start';
wait(10);
form1.Caption := 'done';
end;

Comments

  1. I can't seem to get the example code to ever timeout. What am I missing?

    ReplyDelete
  2. Great Nice topic. its very interesting about Delphi. Great Nice topic. its very interesting about Delphi. thanks for sharing .thanks for sharing .

    ReplyDelete

Post a Comment

Popular posts from this blog

Quricol - QR code generator library

Quricol 2.0 - QR Code generator

Diswy - freeware application to show or hide desktop icons