multithreading - How to wait until a process terminates before continuing to execute - C# -


so launch bunch of process convert audio files , want main program wait until of process complete before executing.

        system.diagnostics.process process = new system.diagnostics.process();         system.diagnostics.processstartinfo stratinfo = new system.diagnostics.processstartinfo();         stratinfo.windowstyle = system.diagnostics.processwindowstyle.hidden;         directoryinfo di = new directoryinfo(@dir);         foreach (fileinfo fi in di.getfiles())             {                 stratinfo.filename = "c:\\audioextract.exe";                 stratinfo.arguments = "-a \"" + dir + "\\" + fi.name + "\"";                 process.startinfo = stratinfo;                 process.start();             }                 foreach (process clsprocess in process.getprocesses())                 {                     if (clsprocess.processname.contains("audioextract.exe"))                     {                         statuslbl.text = "found!";                     }                 } 

thats have see if running, need continue updating getprocesses , check if still running , im not quite sure how.

my app launches many of same process different audio files, simultaneously. looked @ link in comment , set event handler, how handle many of same event everytime 1 of processes exit?

inside if, try

pprocess.waitforexit(); break; 

http://msdn.microsoft.com/en-us/library/fb4aw7b8.aspx

that code wait until process exits, break foreach allowing main program continue running.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -