private static bool ConsoleCloseCheck(ControlSignalType ctrlType) { _forceClosed = true; // Set the flag incase the user pressed Ctrl+C or break etc, exit the main thread if (_pipeProxy == null) { return(true); // We are already shutdown } Log.WriteSystemEventLog("MCEBuddy engine app shutting down", EventLogEntryType.Information); Console.WriteLine("\r\n\n\n\nStopping..."); try { if (_pipeProxy != null) { _pipeProxy.StopBySystem(); } } catch { } try { if (_host != null) { _host.Abort(); // incase we are in faulted state with some resource being held otherwise close takes a long time } } catch { } _pipeProxy = null; // We are done here, free to start another engine _host = null; Console.WriteLine("\r\nStopped"); // Restart the the Windows we stopped earlier Log.WriteSystemEventLog("Trying to start MCEBuddy engine service.", EventLogEntryType.Information); WindowsService.StartService(GlobalDefs.MCEBUDDY_SERVICE_NAME); Log.WriteSystemEventLog("MCEBuddy engine app shutdown complete.", EventLogEntryType.Information); return(true); }
private static bool ConsoleCloseCheck(ControlSignalType ctrlType) { _forceClosed = true; // Set the flag incase the user pressed Ctrl+C or break etc, exit the main thread if (_pipeProxy == null) return true; // We are already shutdown Log.WriteSystemEventLog("MCEBuddy engine app shutting down", EventLogEntryType.Information); Console.WriteLine("\r\n\n\n\nStopping..."); try { if (_pipeProxy != null) _pipeProxy.StopBySystem(); } catch { } try { if (_pipeFactory != null) _pipeFactory.Abort(); // incase we are in a faulted state } catch { } try { if (_host != null) _host.Abort(); // incase we are in faulted state with some resource being held otherwise close takes a long time } catch { } _pipeProxy = null; // We are done here, free to start another engine _pipeFactory = null; _host = null; Console.WriteLine("\r\nStopped"); // Restart the the Windows we stopped earlier Log.WriteSystemEventLog("Trying to start MCEBuddy engine service.", EventLogEntryType.Information); WindowsService.StartService(GlobalDefs.MCEBUDDY_SERVICE_NAME); Log.WriteSystemEventLog("MCEBuddy engine app shutdown complete.", EventLogEntryType.Information); return true; }