如何在没有冻结的情况下延迟 - Inno Setup

如何在没有冻结的情况下延迟 - Inno Setup

问题描述:

您好,我想知道如何在Inno Setup Pascal Script中延迟指定时间的工作(或命令)。如何在没有冻结的情况下延迟 - Inno Setup

内置Sleep(const Milliseconds: LongInt)冻结睡眠时的所有工作。

而我实现的以下功能也使得WizardForm无响应,但不像建在Sleep()函数中那样冻结。

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

我也看了this,但怎么也想不到在我的函数中使用它。

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

在此先感谢您的帮助。

+0

你想延迟什么“工作”? 'WaitForSingleObject'不会有助于防止冻结。无响应和冻结有什么区别? –

+0

好的,不同的是,使用'Sleep'时,WizardForm不是活动窗口,但是当使用SleepEx时它仍然是活动窗口,但会冻结。 :-( – Blueeyes789

+0

我想推迟一个'ssPostInstall'命令:-( – Blueeyes789

使用自定义进度网页(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调用水泵窗口消息队列,是什么阻止了冻结。

enter image description here


虽然实际上,你不想固定长度的套环,而不是使用一个不确定的进度栏和查询循环其状态的DLL。

对此,请参阅Inno Setup: Marquee style progress bar for lengthy synchronous operation in C# DLL