title: To exit the console window in a C# console application
body: <p>I want to exit the console window as soon as my files are written in folder at back end, but no matter whatever I try,</p>
  <pre><code>Environment.exit(0);
  Environment.exit(1);
  Environment.exit(-1);
  </code></pre>
  <p>Also since I am executing from the <em>Main</em> method, I am returning the value, but still my console window doesn't go off even after files are written to the destination folder.</p>
  <p>Below is my code,</p>
  <pre><code>static void Main(string[] args)
  {
      string execute = &quot;&quot;;
      execute = data_info_pooling(args[0], args[1], args[2]);
      Environment.Exit(0);
  }
  </code></pre>
  <p>Also I tried for using <code>Application.exit();</code>, but I am not able to get Application in drop-down box. I have explored almost all the possible helping links from Stack Overflow and searched for any help, but I have no idea where I am going wrong.</p>
  <p>I am trying to run this console application by opening the command prompt and then executing the command as below</p>
  <pre class="lang-none prettyprint-override"><code>cd &quot;Project Path\Debug&quot;
  &quot;Project.exe&quot; &quot;First Parameter&quot; &quot; Second Parameter&quot; &quot;Third Parameter&quot;`,
  </code></pre>
  <p>After files are written in the destination folder, the console window waits and after pressing <kbd>Enter</kbd> it just gives the path again to execute, but I want the window to exit as soon as the task of writing files is completed.</p>
  <h3>Second version of the code</h3>
  <p>I have deleted the <em>for</em> loop which is not necessary. Actually, I was wrong in application of my logic and apologize for my mistake. Some of the below comments helped me to realize my mistake. It's finally
  <code>Environment.exit();</code></p>
  <p>Which works. Also I would like to give a try to another answer of forming batch.</p>