Beispiel #1
0
 /// <summary>
 /// Starts the stop service on target machine.
 /// </summary>
 /// <param name="timeout"></param>
 /// <param name="service"></param>
 protected virtual void Stop(TimeSpan timeout, string service)
 {
     try
     {
         using (Common.Util.ServiceControl sc = new Common.Util.ServiceControl(_serverName, service))
         {
             if (sc.IsRunning)
             {
                 sc.WaitForStop(timeout);
             }
         }
     }
     catch (Exception e)
     {
         throw new ManagementException(e.Message, e);
     }
 }
Beispiel #2
0
        protected virtual bool isServiceRunning(TimeSpan timeout, string service)
        {
            bool isRunning = false;

            try
            {
                using (Common.Util.ServiceControl sc = new Common.Util.ServiceControl(_serverName, service))
                {
                    if (sc.IsRunning)
                    {
                        isRunning = true;
                    }
                }
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
            return(isRunning);
        }
Beispiel #3
0
        /// <summary>
        /// Starts the stop service on target machine.
        /// </summary>
        /// <param name="timeout"></param>
        /// <param name="service"></param>
        protected virtual void Stop(TimeSpan timeout, string service)
        {
            try
            {
#if NETCORE
                if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux))
                {
                    throw new Exception("Failed to stop service. Please try the operation manually.");
                }
#endif
                using (Common.Util.ServiceControl sc = new Common.Util.ServiceControl(_serverName, service))
                {
                    if (sc.IsRunning)
                    {
                        sc.WaitForStop(timeout);
                    }
                }
            }
            catch (Exception e)
            {
                throw new ManagementException(e.Message, e);
            }
        }