Eric Bergman-Terrell's Blog

.NET Programming Tip: How to Exit from a Console Application
October 4, 2010

Use Environment.Exit to immediately return from a console application with a specified result code.

using System;

namespace ConsoleApplication1
{
  class Class1
  {
    [STAThread]
    static void Main(string[] args)
    {
      Console.WriteLine("About to exit");

      int exitCode = 0;
      Environment.Exit(exitCode);

      // This line is not executed.
      Console.WriteLine("After exit");
    }
  }
}
Keywords: Console Application, Environment.Exit

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
Java Programming Tip: SWT Photo Frame ProgramOctober 31, 2016
Vault 3 (Desktop) Version 1.63 ReleasedSeptember 9, 2016
"Compliance with Court Orders Act of 2016"April 9, 2016
Disable "Visual Voicemail" on Android / T-MobileJanuary 17, 2016
IPv6 HumorDecember 10, 2015
Java Programming Tip: Specify the JVM time zoneDecember 7, 2015
Node.js / Express Programming Tip: Detect and Fix Memory LeaksOctober 27, 2015