protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _coordinator.Dispose(); } _disposed = true; }
void ShutdownCoordinator() { try { _log.Info("[Topshelf] Stopping"); _coordinator.Stop(); } catch (Exception ex) { _log.Error("The service did not shut down gracefully", ex); } finally { _coordinator.Dispose(); _coordinator = null; _log.Info("[Topshelf] Stopped"); } }
public void Start() { CheckToSeeIfWinServiceRunning(); "Daemon loading in console...".ToDebug <IDaemon>(); var externalTriggeredTerminatation = new ManualResetEvent(false); var waitHandles = new WaitHandle[] { externalTriggeredTerminatation }; Console.CancelKeyPress += delegate { "Exiting.".ToInfo <IDaemon>(); ServiceCoordinator.Stop(); ServiceCoordinator.Dispose(); externalTriggeredTerminatation.Set(); }; ServiceCoordinator.Start(); "Daemon started, press Control+C to exit." .ToInfo <IDaemon>(); WaitHandle.WaitAny(waitHandles); }
protected override void OnStop() { try { _log.Info("[Topshelf] Stopping"); _coordinator.Stop(); } catch (Exception ex) { _log.Fatal("The service did not shut down gracefully", ex); throw; } finally { _coordinator.Dispose(); _coordinator = null; _log.Info("[Topshelf] Stopped"); } }
public void Run() { _log.Debug("Starting up as a console application"); var internalallyTriggeredTermination = new ManualResetEvent(false); var externalTriggeredTerminatation = new ManualResetEvent(false); var waitHandles = new WaitHandle[] { internalallyTriggeredTermination, externalTriggeredTerminatation }; _coordinator.Stopped += (() => internalallyTriggeredTermination.Set()); Console.CancelKeyPress += delegate { _log.Info("Control+C detected, exiting."); _log.Info("Stopping the service"); _coordinator.Stop(); //user stop _coordinator.Dispose(); externalTriggeredTerminatation.Set(); }; _coordinator.Start(); //user code starts _log.InfoFormat("The service is running, press Control+C to exit."); WaitHandle.WaitAny(waitHandles); //will wait until a termination trigger occurs }