In C#, I can start a process with
process.start(program.exe);
How do I tell if the program is still running, or if it closed?
MSDN System.Diagnostics.Process
If you want to know right now, you can check the HasExited
property.
var isRunning = !process.HasExited;
If it's a quick process, just wait for it.
process.WaitForExit();
If you're starting one up in the background, subscribe to the Exited event after setting EnableRaisingEvents to true.
process.EnableRaisingEvents = true; process.Exited += (sender, e) => { /* do whatever */ };
Process p = new Process(); p.Exited += new EventHandler(p_Exited); p.StartInfo.FileName = @"path to file"; p.EnableRaisingEvents = true; p.Start(); void p_Exited(object sender, EventArgs e) { MessageBox.Show("Process exited"); }
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