void StopService() { try { if (_hasCancelled == false) { _log.InfoFormat("Stopping the {0} service", _settings.ServiceName); if (!_serviceHandle.Stop(this)) { throw new TopshelfException("The service failed to stop (returned false)."); } } } catch (Exception ex) { _log.Error("The service did not shut down gracefully", ex); } finally { _serviceHandle.Dispose(); _log.InfoFormat("The {0} service has stopped.", _settings.ServiceName); } }
public TopshelfExitCode Run() { var exitCode = TopshelfExitCode.AbnormalExit; try { exitCode = TopshelfExitCode.StartServiceFailed; _log.InfoFormat("The {0} service is being started.", _settings.ServiceName); _serviceHandle.Start(this); _log.InfoFormat("The {0} service was started.", _settings.ServiceName); Thread.Sleep(100); exitCode = TopshelfExitCode.StopServiceFailed; _log.InfoFormat("The {0} service is being stopped.", _settings.ServiceName); _serviceHandle.Stop(this); _log.InfoFormat("The {0} service was stopped.", _settings.ServiceName); exitCode = TopshelfExitCode.Ok; } catch (Exception ex) { _settings.ExceptionCallback?.Invoke(ex); _log.Error("The service threw an exception during testing.", ex); } finally { _serviceHandle.Dispose(); } return(exitCode); }
public override void OnStop() { try { _log.Info("[Topshelf] Stopping"); if (!_serviceHandle.Stop(this)) { throw new TopshelfException("The service did not stop successfully (return false)."); } _log.Info("[Topshelf] Stopped"); } catch (Exception ex) { _log.Fatal("The service did not shut down gracefully", ex); throw; } if (_unhandledException != null) { _log.Info("[Topshelf] Unhandled exception detected, rethrowing to cause application to restart."); throw new InvalidOperationException("An unhandled exception was detected", _unhandledException); } }
private void RestartService(ServiceListViewItem serviceListViewItem) { try { using (ServiceControlManager scm = ServiceControlManager.Connect(Advapi32.ServiceControlManagerAccessRights.Connect)) { using (ServiceHandle serviceHandle = scm.OpenService(serviceListViewItem.ServiceName, Advapi32.ServiceAccessRights.QueryStatus | Advapi32.ServiceAccessRights.Start | Advapi32.ServiceAccessRights.Stop)) { Advapi32.ServiceStatusProcess status = serviceHandle.QueryServiceStatus(); //Stop service (throws an exception if it is stopped) serviceHandle.Stop(); //Wait for stop serviceHandle.WaitForStatus(Advapi32.ServiceCurrentState.Stopped, TimeSpan.FromSeconds(10)); //Start service serviceHandle.Start(); } } } catch (System.TimeoutException) { MessageBox.Show(_resManager.GetString("timeout_exception_service_restart"), _resManager.GetString("error"), MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, _resManager.GetString("error"), MessageBoxButton.OK, MessageBoxImage.Error); } }
public TopshelfExitCode Run() { try { _log.InfoFormat("The {0} service is being started.", _settings.ServiceName); _serviceHandle.Start(this); _log.InfoFormat("The {0} service was started.", _settings.ServiceName); Thread.Sleep(100); _log.InfoFormat("The {0} service is being stopped.", _settings.ServiceName); _serviceHandle.Stop(this); } catch (Exception ex) { _log.Error("The service did not shut down gracefully", ex); } finally { _serviceHandle.Dispose(); _log.InfoFormat("The {0} service was stopped.", _settings.ServiceName); } return(TopshelfExitCode.Ok); }
public void Stop() { var running = Interlocked.Exchange(ref _IsRunning, 0); if (running == 1) { this._log.Info("Service Stop requested, exiting."); _serviceHandle.Stop(this); } Application.ExitThread(); }
private void StopService(ServiceListViewItem serviceListViewItem) { try { using (ServiceControlManager scm = ServiceControlManager.Connect(Advapi32.ServiceControlManagerAccessRights.Connect)) { using (ServiceHandle serviceHandle = scm.OpenService(serviceListViewItem.ServiceName, Advapi32.ServiceAccessRights.Stop)) { serviceHandle.Stop(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, _resManager.GetString("error"), MessageBoxButton.OK, MessageBoxImage.Error); } }
private void StopService() { _logWriter.InfoFormat(Resources.StoppingService, _settings.ServiceName); try { if (!_serviceHandle.Stop(this)) { throw new TopshelfException(string.Format(Resources.ServiceDidntStopSuccessfully, _settings.ServiceName)); } } catch (Exception error) { _logWriter.Fatal(string.Format(Resources.StopServiceFailed, _settings.ServiceName), error); } _logWriter.InfoFormat(Resources.ServiceStopped, _settings.ServiceName); }
protected override void OnStop() { try { _log.Info("[Topshelf] Stopping"); _serviceHandle.Stop(this); } catch (Exception ex) { _log.Fatal("The service did not shut down gracefully", ex); throw; } finally { _log.Info("[Topshelf] Stopped"); } }
protected override void OnStop() { try { _log.Info("[Topshelf] Stopping"); if (!_serviceHandle.Stop(this)) { throw new TopshelfException("The service did not stop successfully (return false)."); } _log.Info("[Topshelf] Stopped"); } catch (Exception ex) { _log.Fatal("The service did not shut down gracefully", ex); ExitCode = (int)TopshelfExitCode.StopServiceFailed; throw; } }
public bool Stop(HostControl hostControl) { return(_serviceHandle.Stop(hostControl)); }
bool ServiceHandle.Stop(HostControl hostControl) { return(_service.Stop(_hostControl)); }
bool ServiceHandle.Stop(HostControl hostControl) { var control = new AppDomainHostControl(this); return(_service.Stop(control)); }