c# - Should I use a using statement/dispose if the object isn't actually going to be used in code? -
this question has answer here:
- what process.dispose() do? 2 answers
i'm working in winforms code right now, , have come across lines several times:
... system.diagnostics.process.start(somefilename); ...
...which kicks off process on client machine, , forgets it. process.start(somefilename)
returns process
type object, implements idisposable
, code not doing object, because whole idea trigger process , forget it.
in case, should process
object still disposed, if we're not keeping in memory @ all? like:
using (system.diagnostics.process.start(somefilename) { }
or
var process = system.diagnostics.process.start(somefilename); process.dispose();
process
objects holds unmanaged resource(s) (hprocess
handle)
public class process : component { // // fields // bool haveprocessid; int processid; bool haveprocesshandle; safeprocesshandle m_processhandle; // <- should disposed bool isremotemachine; string machinename; processinfo processinfo; int32 m_processaccess; ...
and should disposed. using local variable (var process = ...
) looks overshooting in context, that's why suggest
system.diagnostics.process.start(somefilename).close();
Comments
Post a Comment