I'm working in some Winforms code right now, and I have come across lines like this several times:
...
System.Diagnostics.Process.Start(someFileName);
...
...which just kicks off some process on the client machine, and completely forgets about it. Process.Start(someFileName)
returns a Process
type object, which implements IDisposable
, but the code is not doing anything with the object, because the whole idea was to just trigger the process and forget about it.
In this case, should the Process
object still be disposed, if we're not keeping it in memory at all? Something like:
using (System.Diagnostics.Process.Start(someFileName) { }
or
var process = System.Diagnostics.Process.Start(someFileName);
process.Dispose();