Setup中延迟而不冻结

Setup中延迟而不冻结

本文介绍了如何在Inno Setup中延迟而不冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道如何在Inno Setup Pascal脚本中将工作(或命令)延迟指定的时间.

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

内置的Sleep(const Milliseconds: LongInt)可以在睡眠时冻结所有工作.

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

我实现的以下功能也使WizardForm无响应,但不会像Sleep() Function中内置的那样冻结.

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.

我想知道如何在此SleepEx函数中使用WaitForSingleObject.

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

预先感谢您的帮助.

推荐答案

使用自定义进度页( CreateOutputProgressPage函数):

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;

关键是SetProgress调用会弹出窗口消息队列,这可以防止冻结.

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

尽管实际上,您不需要定长循环,而是使用不确定的进度条并在循环中查询DLL的状态.

为此,请参见 Inno设置:字幕样式进度条,用于在C#DLL中进行长时间的同步操作.

这篇关于如何在Inno Setup中延迟而不冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:33