Inno Setup: Marquee style progress bar for lengthy synchronous operation in C# DLL -
i create setup program using inno setup. have code c# , wizard page runs it. want see "progressbar" (style marquee) when code c# works long time. want undectend code c# working or hanging. how create "progressbar" (style marquee) in inno setup code c#. thank idea.
example progressbar:
some code:
[files] source: "getdatabases.dll"; flags: dontcopy [code] function serverofdatabases( scriptname, server, user, password,namedb: string; out strout: widestring): integer; external 'serverofdatabases@files:getdatabases.dll stdcall'; var serverdetailspage: tinputquerywizardpage; function calldb(scriptname, server, user, password, namedb: string):string; var retval: integer; str: widestring; begin retval := serverofdatabases(scriptname, server, user, password, namedb, str); result:= str; end; procedure initializewizard; var ... begin serverdetailspage := createinputquerypage(wpwelcome, '', '', '...'); serverdetailspage.add('server...', false); ... serverdetailspage.values[0] := ''; end; function nextbuttonclick(curpageid: integer): boolean; var datadases: string; ... begin ... if curpageid = serverdetailspage.id begin ... datadases := ''; scriptname := 'listdb'; datadases := calldb( scriptname, serverdetailspage.values[0], serverdetailspage.values[2], serverdetailspage.values[3], ''); ... end; end;
this not easy. calling synchronous function blocks gui thread. cannot animate progress bar.
you have run lengthy task on different thread. seems dll, can modify offer asynchronous api. like:
private static task _task = null; private static int _outcome; [dllexport(callingconvention = callingconvention.stdcall)] public static void startsomething() { // starts operation on different thread _task = new task(() => { something(); }); _task.start(); } // operation run on different thread private static void something() { // lengthy operation thread.sleep(10000); // remember results _outcome = 123; } [dllexport(callingconvention = callingconvention.stdcall)] public static bool hassomethingcompleted(out int outcome) { // check if operation has completed bool result = _task.iscompleted; // , collect results outcome = _outcome; return result; }
and can use inno setup like:
procedure initializewizard(); begin serverdetailspage := createinputquerypage(wpwelcome, '', '', '...'); end; procedure calldll; var progresspage: toutputprogresswizardpage; outcome: integer; begin startsomething; progresspage := createoutputprogresspage('calling dll', ''); progresspage.show; try progresspage.setprogress(0, 100); progresspage.progressbar.style := npbstmarquee; { wait finish } while not hassomethingcompleted(outcome) begin { , pump windows message queue animate progress bar } progresspage.setprogress(0, 100); sleep(50); end; progresspage.hide; progresspage.free; end; msgbox(format( 'something has finished , outcome %d', [outcome]), mbinformation, mb_ok); end; function nextbuttonclick(curpageid: integer): boolean; begin if curpageid = serverdetailspage.id begin calldll; end; result := true; end;
for similar question see:
how delay without freezing - inno setup
wiki
Comments
Post a Comment