Search code examples
c#processprocessstartinfo

C# Using ProcessStartInfo and Process.HasExited


I want to use ProcessStartInfo to startup programs from my C# application. I am using ProcessStartInfo insted of normal Process because I want to startup programs minimized so I will be using ProcessWindowStyle.Minimized and maybe I will also pass some arguments. I also want to monitor those started applications after so I want to use for example Process.HasExited property (and also PeakWorkingSet64) but I can't as I got an error 'System.Diagnostics.ProcessStartInfo' does not contain a definition for 'HasExited'. Is there any way to start applications with ProcessStartInfo and also using properties that are available with standard Process class?


Solution

  • ProcessStartInfo is a class that defines settings that you want to pass into an overload of Process.Start.

    So, you would typically do something like this:

    var psi = new ProcessStartInfo { ... };
    var process = Process.Start("C:\myProgram.exe", psi);
    process.Exited += myProcessExitHandler;