Dev2.WindowsServiceManager.StartService C# (CSharp) Method

StartService() public static method

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

            try
            {
                var controller = new ServiceController(AppSettings.ServiceName);

                if (controller.Status != ServiceControllerStatus.Stopped)
                {
                    throw new Exception(string.Format("Can't start the service because it is in the '{0}' state.",
                        controller.Status));
                }

                controller.Start();
                LogMessage("Service started successfully.", context);
                LogMessage("Setting Recovery Options.", null);
                SetRecoveryOptions();
                LogMessage("Recovery Options successfully set.", null);
            }
            catch (Exception ex)
            {
                result = false;
                LogMessage(
                    "An error occurred while starting the service, please start it manually or reboot the computer.",
                    context);
                WriteExceptions(ex, context);
            }

            return result;
        }