How to Delay without freezing - Inno Setup

荒凉一梦 提交于 2019-11-30 16:18:33

问题


Hello I like to know how can I delay a work (or a command) for a specified time in Inno Setup Pascal Script.

The built in Sleep(const Milliseconds: LongInt) freezes all work while sleeping.

And the following function I implemented also makes the WizardForm unresponsive but not freezing like built in Sleep() Function.

procedure SleepEx(const MilliSeconds: LongInt);
begin
  ShellExec('Open', 'Timeout.exe', '/T ' + IntToStr(MilliSeconds div 1000), '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
end;

I also read this, but can't think how to use it in my Function.

I like to know how can I use WaitForSingleObject in this SleepEx Function.

Thanks in Advance for Your Help.


回答1:


Use a custom progress page (the CreateOutputProgressPage function):

procedure CurStepChanged(CurStep: TSetupStep);
var 
  ProgressPage: TOutputProgressWizardPage;
  I, Step, Wait: Integer;
begin
  if CurStep = ssPostInstall  then
  begin
    { start your asynchronous process here }

    Wait := 5000;
    Step := 100; { smaller the step is, more responsive the window will be }
    ProgressPage :=
      CreateOutputProgressPage(
        WizardForm.PageNameLabel.Caption, WizardForm.PageDescriptionLabel.Caption);
    ProgressPage.SetText('Doing something...', '');
    ProgressPage.SetProgress(0, Wait);
    ProgressPage.Show;
    try
      { instead of a fixed-length loop, query your asynchronous process completion/state }
      for I := 0 to Wait div Step do
      begin
        { pumps a window message queue as a side effect, what prevents the freezing }
        ProgressPage.SetProgress(I * Step, Wait);
        Sleep(Step);
      end;
    finally
      ProgressPage.Hide;
      ProgressPage.Free;
    end;
  end;
end;

The key point here is, that the SetProgress call pumps a window message queue, what prevents the freezing.


Though actually, you do not want the fixed-length loop, instead you use an indeterminate progress bar and query the DLL in the loop for its status.

For that, see Inno Setup: Marquee style progress bar for lengthy synchronous operation in C# DLL.



来源:https://stackoverflow.com/questions/39825271/how-to-delay-without-freezing-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!