In the following example, what happens to the process if it is still running once the code leaves the using statement?
using (var p = new Process())
{
p.StartInfo.FileName = "c:\\temp\\SomeConsoleApp.exe";
p.Start();
}
One should separate the OS process that is running on your system from the Process object that represents a "handle" to it in your program:
Process object gets disposed, so your program can no longer interact with the OS process.Call of Dispose() method on the Process object does not kill the OS process.
As you might know using statement will call Dispose method, so the process instance will be Disposed.
To interact with the process, to get the process related information you need Handle to the Process. .Net framework internally holds the Handle to the process and takes all the pain for you. Dispose will close the process Handle and thus you'll not be able to make use of Process object in a good way anymore.
And most important thing: Nothing happens to the process which you started, it runs as if nothing happens. Really nothing happened, you just lost the key to the door, doesn't mean that room is destroyed.
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