I have following code, but why is the ProcessExited
method never called? It is the same if I don't a use Windows shell (startInfo.UseShellExecute = false
).
ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = true; startInfo.UseShellExecute = true; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.FileName = path; startInfo.Arguments = rawDataFileName; startInfo.WorkingDirectory = Util.GetParentDirectory(path, 1); try { Process correctionProcess = Process.Start(startInfo); correctionProcess.Exited += new EventHandler(ProcessExited); correctionProcess.WaitForExit(); status = true; }
.....
internal void ProcessExited(object sender, System.EventArgs e) { //print out here }
Be sure you save the Process object if you use the static Process. Start() call (or create an instance with new ), and then either check the HasExited property, or subscribe to the Exited event, depending on your needs. You can use the Process. Start(string) method since it returns an instance of Process.
The EnableRaisingEvents property is used in asynchronous processing to notify your application that a process has exited.
In order to receive a callback on Exited
event, the EnableRaisingEvents
must be set to true.
Process correctionProcess = Process.Start(startInfo); correctionProcess.EnableRaisingEvents = true; correctionProcess.Exited += new EventHandler(ProcessExited);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With