The definitive code that prevents a c# console app from exiting [until custom cleanup code has completed]
问题 Can we work together to come up with something that works for control-c, control-break, log off, window X button pressed, etc? Here is what I have so far: class Program { private static ConsoleEventHandlerDelegate consoleHandler; delegate bool ConsoleEventHandlerDelegate(CtrlTypes eventCode); static void Main(string[] args) { consoleHandler = new ConsoleEventHandlerDelegate(ConsoleCtrlCheck); SetConsoleCtrlHandler(consoleHandler, true); System.Diagnostics.Process.GetCurrentProcess().Exited +=