protected virtual bool isServiceRunning(TimeSpan timeout, string service) { bool isRunning = false; try { using (ServiceControl sc = new ServiceControl(_serverName, service)) { if (sc.IsRunning) { isRunning= true; } } } catch (Exception e) { throw new ManagementException(e.Message, e); } return isRunning; }
/// <summary> /// Starts the restart service on target machine. /// </summary> /// <param name="timeout"></param> /// <param name="service"></param> protected virtual void Restart(TimeSpan timeout, string service) { try { using (ServiceControl sc = new ServiceControl(_serverName, service)) { if (sc.IsRunning) { sc.WaitForStop(timeout); sc.WaitForStart(timeout); } } } catch (Exception e) { throw new ManagementException(e.Message, e); } }