示例#1
0
 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;
 }
示例#2
0
 /// <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);
     }
 }