public void Run() { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); _osCommands.CheckToSeeIfServiceRunning(_description); try { _log.Debug("Starting up as a console application"); _exit = new ManualResetEvent(false); Console.CancelKeyPress += HandleCancelKeyPress; _coordinator.Start(); //user code starts _log.InfoFormat("[Topshelf] Running, press Control+C to exit."); _exit.WaitOne(); } catch (Exception ex) { _log.Error("An exception occurred", ex); } finally { ShutdownCoordinator(); _exit.Close(); } }
protected override void OnStart(string[] args) { try { _log.Info("[Topshelf] Starting"); _log.DebugFormat("[Topshelf] Arguments: {0}", string.Join(",", args)); _coordinator.Start(); } catch (Exception ex) { _log.Fatal(ex); throw; } }
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); }
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 }
protected override void OnStart(string[] args) { ServiceCoordinator.Start(); }