protected override void Execute(CodeActivityContext context) { TimeSpan timeOut = Timeout.Get(context); if (timeOut.TotalSeconds <= 0) { timeOut = new TimeSpan(0, 0, 30); } try { ServiceController serviceController = new ServiceController(Name.Get(context), (string.IsNullOrEmpty(MachineName.Get(context)) ? "." : MachineName.Get(context))); if (serviceController.Status == ServiceControllerStatus.Running) { serviceController.Stop(); serviceController.WaitForStatus(ServiceControllerStatus.Stopped, timeOut); } } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.Message == "The service has not been started") { return; } throw; } }
protected override void Execute(CodeActivityContext context) { TimeSpan timeOut = Timeout.Get(context); if (timeOut.TotalSeconds <= 0) { timeOut = new TimeSpan(0, 0, 30); } try { ServiceController serviceController = new ServiceController(Name.Get(context), (string.IsNullOrEmpty(MachineName.Get(context)) ? "." : MachineName.Get(context))); switch (serviceController.Status) { case ServiceControllerStatus.Stopped: case ServiceControllerStatus.Paused: serviceController.Start(); serviceController.WaitForStatus(ServiceControllerStatus.Running, timeOut); break; } } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.Message == "An instance of the service is already running") { return; } throw; } }
protected override void Execute(CodeActivityContext context) { try { ServiceController serviceController = new ServiceController(Name.Get(context), (string.IsNullOrEmpty(MachineName.Get(context)) ? "." : MachineName.Get(context))); ChangeStartMode(serviceController, StartMode.Get(context)); } catch (Exception) { throw; } }