How to exit from a console application
Posted: Thu Dec 31, 2009 9:08 am
Use Environment.Exit to immediately return from a console application with a specified result code.
Code: Select all
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");
}
}
}