.NET console application exit event

You can use the ProcessExit event of the AppDomain: class Program { static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); // do some work } static void CurrentDomain_ProcessExit(object sender, EventArgs e) { Console.WriteLine(“exit”); } } Update Here is a full example program with an empty “message pump” running on a separate thread, that allows … Read more