title: Use of Process with using block
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/185314/what-happens-if-i-dont-close-a-system-diagnostics-process-in-my-c-console-app">What happens if I don&#39;t close a System.Diagnostics.Process in my C# console app?</a>  </p>
  </blockquote>
  
  
  
  <p>As <code>System.Diagnostics.Process</code> inherits from <code>Component</code> which implements <code>IDisposable</code>, should I always create a <code>Process</code> with a <code>using</code> block?</p>
  
  <p>For example, this...:</p>
  
  <pre><code>using (var process = new Process())
  {
      process.StartInfo.FileName = "some process.exe";
      process.Start();
      process.WaitForExit();
  }
  </code></pre>
  
  <p>...instead of this:</p>
  
  <pre><code>var process = new Process
      { 
          StartInfo = { FileName = "some process.exe" }
      };
  process.Start();
  process.WaitForExit();
  </code></pre>
  
  <p>I ask because I've rarely seen <code>Process</code> appear in a <code>using</code> block; for example the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx" rel="nofollow noreferrer">MSDN page</a> for <code>Process</code> does not use it. Having the use of the object initializer is helpful too.</p>
  
  <p>If I <em>should</em> be using it, should I then go and 'retrofit' it to my existing codebase?</p>
  
  <p>What might be the consequences if this were not done? (Assuming <code>WaitForExit()</code> is being called correctly in each case.)</p>