Dev2.WindowsServiceManager.StopService C# (CSharp) Method

StopService() public static method

public static StopService ( System.Configuration.Install.InstallContext context ) : bool
context System.Configuration.Install.InstallContext
return bool
        public static bool StopService(InstallContext context)
        {
            bool result = true;

            try
            {
                var controller = new ServiceController(AppSettings.ServiceName);
                if (controller.Status != ServiceControllerStatus.Running)
                {
                    throw new Exception(string.Format("Can't stop the service because it is in the '{0}' state.",
                        controller.Status));
                }

                controller.Stop();
                LogMessage("Service stopped successfully.", context);
            }
            catch (Exception ex)
            {
                result = false;
                LogMessage(
                    "An error occurred while start the service, please start it manually or reboot the computer.",
                    context);
                WriteExceptions(ex, context);
            }

            return result;
        }