views:

78

answers:

2

When you are starting a process and dont care about the result is this ok?

Process.Start(xxx);

Or should you do this

using (Process.Start(xxx)){}
+5  A: 

Looking at the implementation of the Process.dispose(bool) method shows that it calls Close() on the Process instance. This in turn cleans up the native process handle so its probably not a bad idea.

It also cleans up a wait handle that it uses to check if the process has exited.

Even if you don't use the using (...) block the finalizer will catch these resources in the end.

Luke Quinane
+1  A: 

The Process object that is returned by Process.Start contains a Windows process HANDLE, so it should be disposed once you no longer need to use the Process object.

If you don't need to use the returned Process object at all, then the empty using block that you show is fine. Note that disposing the Process releases the handle but it (fortunately) does not stop the process from executing.

binarycoder