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
.NET Public-Key (Asymmetric) Cryptography DemoJuly 20, 2025
Raspberry Pi 3B+ Photo FrameJune 17, 2025
EBTCalc (Android) Version 1.53 is now availableMay 19, 2024
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021