Shaitan00 Posted December 7, 2005 Posted December 7, 2005 At a certain point in my program I need to launch a program [oApp.exe] with a specific command line parameter. To accomplish this I used the Process class as shown in the code below: Process.Start("oApp.exe", "c:\\text.txt"); This will launch oApp.exe (with command line parameter C:\Text.txt) which should take 5-10mins to process. Problem is, I want my code to WAIT for this process to complete/finsish (the 5-10mins) before going forward seeing as the next line of code assumes that the Text.txt was processed. The way it is now, the process is launched and them my code continues (it does not wait) which consequently causes a huge amount of fatal errors further down. So, how do I WAIT for my Process to complete? Do I have to actually make a Process variable? Process pApp = new Process(); pApp.StartInfo.FileName = "oApp.exe"; pApp.StartInfo.Arguments = "C:\\text.txt"; pApp.Start(); But that also doesn't WAIT - however I assume it gives us more control.... Any help/hints would be much appreciated. Thanks, Quote
techmanbd Posted December 7, 2005 Posted December 7, 2005 this is wha I do. This is in VB but easy to translate I am sure for C put after the pApp.start Do While Not pApp.HasExited Application.DoEvents() Loop Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
*Experts* DiverDan Posted December 7, 2005 *Experts* Posted December 7, 2005 Another way is to use the .WaitForExit properity with pApp. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Leaders snarfblam Posted December 7, 2005 Leaders Posted December 7, 2005 this is wha I do. This is in VB but easy to translate I am sure for C put after the pApp.start Do While Not pApp.HasExited Application.DoEvents() Loop One drawback with this method is that all of the spare CPU power is spent on your application calling DoEvents(). The CPU will be made available when other applications need it, but the end user might notice some unusual behavior. If you look in the task manager you will see CPU usage jump to 100%. If the user has a variable speed CPU fan, he will hear it revving up although to him there is no appearent intense use of the CPU. Quote [sIGPIC]e[/sIGPIC]
Wile Posted December 8, 2005 Posted December 8, 2005 Third way would be to add an event handler to the Exited event on the process. However you have to set the EnableRaisingEvents property to true for the event to work Quote Nothing is as illusive as 'the last bug'.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.