当前位置: 首页 > 技术文档 > 正文
avatar

用sleep来延迟执行,结果程序假死!~ 下面这段代码彻底解决假死的问题。 调用:

b8389b504fc2d562f274e9c3e41190ef76c66c9b
用sleep来延迟执行,结果程序假死!~
下面这段代码彻底解决假死的问题。

procedure TForm1.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;
end;

调用:

delay(10000);
本文固定链接: https://blog.yanhualou.com/jishu/701.html | 烟花楼博客
标签:

delphi 延迟执行程序代码:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter