2016-10-03 87 views
1

您好,我想知道如何在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

回答

1

使用自定義進度網頁(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

相關問題