Cassie Kasandr
Cassie Kasandr

Reputation: 341

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?

Upvotes: 0

Views: 374

Answers (2)

Brian Driscoll
Brian Driscoll

Reputation: 19635

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;

Upvotes: 2

LB2
LB2

Reputation: 4860

ProcessStartInfo is just a structure that describes how to start a process. Once you define it, you pass it to Process.Start() and get back instance of Process. On that instance you can call .HasExited.

Upvotes: 2

Related Questions