static public bool HandleConsoleClose(NativeMethods.CtrlTypes type) { switch (type) { case NativeMethods.CtrlTypes.CTRL_C_EVENT: case NativeMethods.CtrlTypes.CTRL_BREAK_EVENT: case NativeMethods.CtrlTypes.CTRL_CLOSE_EVENT: case NativeMethods.CtrlTypes.CTRL_LOGOFF_EVENT: case NativeMethods.CtrlTypes.CTRL_SHUTDOWN_EVENT: verboseConsoleOutput = true; Logging.consoleOutput = verboseConsoleOutput; Console.WriteLine(); Console.WriteLine("Application is being closed!"); Logging.info("Shutting down..."); Logging.flush(); IxianHandler.shutdown(); // Wait (max 5 seconds) for everything to die DateTime waitStart = DateTime.Now; while (true) { if (Process.GetCurrentProcess().Threads.Count > 1) { Thread.Sleep(50); } else { Console.WriteLine(String.Format("Graceful shutdown achieved in {0} seconds.", (DateTime.Now - waitStart).TotalSeconds)); break; } if ((DateTime.Now - waitStart).TotalSeconds > 30) { Console.WriteLine("Unable to gracefully shutdown. Aborting. Threads that are still alive: "); foreach (Thread t in Process.GetCurrentProcess().Threads) { Console.WriteLine(String.Format("Thread {0}: {1}.", t.ManagedThreadId, t.Name)); } break; } } return(true); } return(true); }
private static bool ConsoleCtrlCheck(NativeMethods.CtrlTypes ctrlType) { service.Shutdown(); return(true); }
private bool OnBreakReceived(NativeMethods.CtrlTypes ctrlType) { Break(); return(true); }