使用自定义进度页(
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
call泵送一个窗口消息队列,这可以防止冻结。
尽管实际上,您并不需要固定长度的循环,而是使用不确定的进度条,并在循环中查询DLL的状态。
为此,请参见
Inno Setup: Marquee style progress bar for lengthy synchronous operation in C# DLL
.