2

when i am using process:

var startInfo = process.StartInfo;
startInfo.FileName = @"C:\cxecute.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

process.Start();

is it necessary to use process.close?

Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
Assaf Zigdon
  • 461
  • 2
  • 5
  • 9
  • It depends....on what you define necessary – apomene Mar 19 '13 at 15:31
  • I think, this question for you. If it necessary, you must close, otherwise the process will live by its life. – Hamlet Hakobyan Mar 19 '13 at 15:32
  • The documentation says that [``Process.Close()``](http://msdn.microsoft.com/en-gb/library/system.diagnostics.process.close.aspx) will free up the resources –  Mar 19 '13 at 15:34

2 Answers2

4

The Process type does contain resources it frees on calls to Close and it implements IDisposable. Hence it should be treated like any other IDisposable object and have Dispose called when you are done using it.

Failing to call Dispose won't cause any direct issues with the use of the Process object though. It's not like FileStream where failing to call Close can prevent other FileStream instances over the same file. That being said, you should still call Close when you are done with it.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
0

Process implements IDisposable. It is better to Free resource allocated by the Process.

Process.Close() - Frees all the resources that are associated with this component.

So yes if the process must be Closed/Disposed

Parimal Raj
  • 20,189
  • 9
  • 73
  • 110