c# - Run silent install in different thread - searching for solution without busy waiting -


i'm building installer project need dowload many installation files internet (downlading operation executed in parallel) , start installing files 1 one. installing sequence not important. when file complete downloaded inserted queue , have other worker taking queue files , install them 1 one. implemented , have problem in installation process.

i'm installing downloaded files in silent mode wih next method:

        private void install()         {             var item = _installitems.dequeue();              item.progstage = progressstage.install;             refreshpgbars();             system.diagnostics.processstartinfo psi = new system.diagnostics.processstartinfo();            //insert psi arguments , file name here                system.diagnostics.process.start(psi);//start installing } 

i calling method background thread:

        thread worker = new thread(() => install());         worker.isbackground = true;         worker.start();         worker.join(); 

it seems join method not know when installation finished - code not delayed @ on worker.join(); line.

i tried insert next code @ end of install() method in order solve it:

           while (installerprocess.hasexited == false)             {                 system.threading.thread.sleep(500);             } 

and solve thread.sleep() freezing entire app , proivde terrible user experience. found solution includs task , "busy waiting" loop i'm searching better solution (more efficient one).

btw i'm working .net 4.

any ideas? thanks

process.start start process , not wait complete. hence thread on start process. assuming installer process exit after installation complete, can modify code way:

private void install()         {             var item = _installitems.dequeue();              item.progstage = progressstage.install;             refreshpgbars();             system.diagnostics.processstartinfo psi = new system.diagnostics.processstartinfo();            //insert psi arguments , file name here                process installproc = system.diagnostics.process.start(psi);//start installing             installproc.waitforexit(); } 

to guarantee sequential installs, make sure dequeue() _installitems in 1 thread , run install process thread only.. dequeue() again .. in loop.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -