How to Detect Process Exit
Sometimes it is a common task in .NET applications to start some command-line process using System.Diagnostics.Process. Like so:
Process proc = new Process(); proc.StartInfo.FileName = "mycommand.cmd"; proc.Start();
However it is a bit more complicated task to determine when the Process exited or the command finished its work. 2 handy properties of Process would help: HasExited and WaitForExit:
do { if (!proc.HasExited) { proc.Refresh(); } } while (!proc.WaitForExit(1000)); // exited here - do work
Enjoy :)
Friday, July 6, 2007 11:55 PM