コード例 #1
0
        protected void StartService()
        {
            try
            {
                if (_machineName == null)
                {
                    logger.Debug("StartService(" + _service + ")");
                }
                else
                {
                    logger.Debug("StartService(" + _service + ", " + _machineName + ")");
                }

                _serviceController.Refresh();
                switch (_serviceController.Status)
                {
                case ServiceControllerStatus.ContinuePending:
                    break;

                case ServiceControllerStatus.Paused:
                    _serviceController.Continue();
                    break;

                case ServiceControllerStatus.PausePending:
                    _serviceController.WaitForStatus(ServiceControllerStatus.Paused, new TimeSpan(0, _startTimeout, 0));
                    _serviceController.Continue();
                    break;

                case ServiceControllerStatus.Running:
                    break;

                case ServiceControllerStatus.StartPending:
                    break;

                case ServiceControllerStatus.Stopped:
                    _serviceController.Start();
                    break;

                case ServiceControllerStatus.StopPending:
                    _serviceController.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, _startTimeout, 0));
                    _serviceController.Start();
                    break;
                }

                _serviceController.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, _startTimeout, 0));
            }
            catch (System.ServiceProcess.TimeoutException ex)
            {
                if (_machineName == null)
                {
                    logger.Debug("StartService: Timeout starting service [" + _service + "].");
                    throw new PeachException("Error, WindowsService monitor was unable to start service [" + _service + "].", ex);
                }
                else
                {
                    logger.Debug("StartService: Timeout starting service [" + _service + "] on computer [" + _machineName + "].");
                    throw new PeachException("Error, WindowsService monitor was unable to start service [" + _service + "] on computer [" + _machineName + "].", ex);
                }
            }
        }
コード例 #2
0
        public static async Task <bool> ContinueService(
            [NotNull] string serviceName,
            CancellationToken token = default(CancellationToken))
        {
            if (serviceName == null)
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                new ServiceControllerPermission(
                    ServiceControllerPermissionAccess.Control,
                    Environment.MachineName,
                    serviceName).Assert();
                using (ServiceController controller = new ServiceController(serviceName, Environment.MachineName))
                    switch (controller.Status)
                    {
                    case ServiceControllerStatus.Running:
                        return(true);

                    case ServiceControllerStatus.ContinuePending:
                    case ServiceControllerStatus.StartPending:
                        return(await WaitForAsync(controller, ServiceControllerStatus.Running, token)
                               .ConfigureAwait(false));

                    case ServiceControllerStatus.Paused:
                        controller.Continue();
                        return(await WaitForAsync(controller, ServiceControllerStatus.Running, token)
                               .ConfigureAwait(false));

                    case ServiceControllerStatus.PausePending:
                        if (!await WaitForAsync(controller, ServiceControllerStatus.Paused, token)
                            .ConfigureAwait(false))
                        {
                            return(false);
                        }
                        controller.Continue();
                        return(await WaitForAsync(controller, ServiceControllerStatus.Running, token)
                               .ConfigureAwait(false));

                    default:
                        return(false);
                    }
            }
            catch (TaskCanceledException)
            {
                return(false);
            }
        }
コード例 #3
0
        private static void EnsureServiceRunning(ServiceController sc)
        {
            switch (sc.Status)
            {
            case ServiceControllerStatus.ContinuePending:
            {
                sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 1, 0));
            }
            break;

            case ServiceControllerStatus.Paused:
            {
                sc.Continue();
                sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 1, 0));
            }
            break;

            case ServiceControllerStatus.PausePending:
            {
                sc.WaitForStatus(ServiceControllerStatus.Paused);
                sc.Continue();
                sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 1, 0));
            }
            break;

            case ServiceControllerStatus.StartPending:
            {
                sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 1, 0));
            }
            break;

            case ServiceControllerStatus.Stopped:
            {
                sc.Start();
                sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 1, 0));
            }
            break;

            case ServiceControllerStatus.StopPending:
            {
                sc.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 1, 0));
                sc.Start();
                sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 1, 0));
            }
            break;

            case ServiceControllerStatus.Running:
            default: break;
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: balanciq/MB_StudentProjects
        public static void Continue(ListView listView1)
        {
            string            s   = listView1.SelectedItems[0].Text;
            ServiceController ser = new ServiceController(s);

            if (ser.CanPauseAndContinue == true)
            {
                ser.Continue();
                ser.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10));
                MessageBox.Show("Служба" + ser.DisplayName + " продолжила выполнение ", "Внимание", MessageBoxButtons.OK,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.DefaultDesktopOnly);
            }
            listView1.Items.Clear();
            foreach (ServiceController service1 in ServiceController.GetServices())
            {
                string serviceName = service1.ServiceName;

                string       serviceDisplayName = service1.DisplayName;
                string       serviceType        = service1.ServiceType.ToString();
                string       status             = service1.Status.ToString();
                string       startType          = service1.StartType.ToString();
                ListViewItem lvi = new ListViewItem(serviceName);
                lvi.SubItems.Add(serviceDisplayName);
                lvi.SubItems.Add(serviceType);
                lvi.SubItems.Add(startType);
                lvi.SubItems.Add(status);
                listView1.Items.Add(lvi);
            }
        }
コード例 #5
0
        /// <summary>
        /// Handles the LinkClicked event of the linkLabelServicePause control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Windows.Forms.LinkLabelLinkClickedEventArgs"/> instance containing the event data.</param>
        private void linkLabelServicePause_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            LinkLabel linkLabel = (LinkLabel)sender;

            //Pas de tag ? il ne se passe rien (n'est pas sensé arrivé grâce à UpdateServiceLinks)
            if (linkLabel.Tag.ToString() == "")
            {
                return;
            }

            try {
                //Lisons le tag du lien pour déterminer le comportement à adopter (pause ou continue)
                if (linkLabel.Tag.ToString() == "Pause")
                {
                    //Démarrage du service
                    sc.Pause();
                }
                else
                {
                    //Arrêt du service
                    sc.Continue();
                }
            } catch (Exception ex) {
                if (Program.options.DebugMode)
                {
                    PrintException(ex);
                }
                labelAutoUpdateException.Text = ex.Message;
                return;
            }
            ProbeService();
        }
コード例 #6
0
        /// <summary>
        /// 恢复服务
        /// </summary>
        /// <param name="serviceName">服务名称</param>
        public static void Continue(string serviceName)
        {
            if (!IsExist(serviceName))
            {
                return;
            }

            ServiceController service = new ServiceController(serviceName);

            try
            {
                if (service.CanPauseAndContinue && (service.Status == ServiceControllerStatus.Paused || service.Status == ServiceControllerStatus.PausePending))
                {
                    service.Continue();
                    service.Refresh();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                service.Dispose();
            }
        }
コード例 #7
0
 private void DoPause()
 {
     try
     {
         ServiceController controller = GetServiceController();
         if (controller == null)
         {
             return;
         }
         WaitDlg.RunProgress("Pause...");
         if (controller.Status == ServiceControllerStatus.Paused || controller.Status == ServiceControllerStatus.PausePending)
         {
             controller.Continue();
             controller.WaitForStatus(ServiceControllerStatus.Running);
         }
         else
         {
             controller.Pause();
             controller.WaitForStatus(ServiceControllerStatus.Paused);
         }
         System.Threading.Thread.Sleep(1000);
         SetServiceStatus(controller);
         ShowServiceDetails();
     }
     finally
     {
         WaitDlg.EndProgress();
     }
 }
コード例 #8
0
        private void btnPauseContinue_Click(object sender, EventArgs e)
        {
            string serviceName = "EmailService";

            try
            {
                ServiceController serviceController = new ServiceController(serviceName);
                if (serviceController.CanPauseAndContinue)
                {
                    if (serviceController.Status == ServiceControllerStatus.Running)
                    {
                        serviceController.Pause();
                        lblLog.Text = "服务已暂停";
                    }
                    else if (serviceController.Status == ServiceControllerStatus.Paused)
                    {
                        serviceController.Continue();
                        lblLog.Text = "服务已继续";
                    }
                    else
                    {
                        lblLog.Text = "服务未处于暂停和启动状态";
                    }
                }
                else
                {
                    lblLog.Text = "服务不能暂停";
                }
            }
            catch (Exception ex)
            {
                _log.Fatal(string.Format("未找到服务:{0} !", serviceName, ex.Message));
            }
        }
コード例 #9
0
 private void btnPauseContinue_Click(object sender, EventArgs e)
 {
     try
     {
         ServiceController serviceController = new ServiceController("ServiceShaka");
         if (serviceController.CanPauseAndContinue)
         {
             if (serviceController.Status == ServiceControllerStatus.Running)
             {
                 serviceController.Pause();
                 lblLog.Text = "服务已暂停";
             }
             else if (serviceController.Status == ServiceControllerStatus.Paused)
             {
                 serviceController.Continue();
                 lblLog.Text = "服务已继续";
             }
             else
             {
                 lblLog.Text = "服务未处于暂停和启动状态";
             }
         }
         else
         {
             lblLog.Text = "服务不能暂停";
         }
     }
     catch (Exception ex)
     {
     }
 }
コード例 #10
0
        private void continueOperation()
        {
            _currentOperation = Operation.Continue;

            try
            {
                _srvController.Continue();
                _srvController.WaitForStatus(ServiceControllerStatus.Running);

                if (FinishedOperation != null)
                {
                    FinishedOperation(this, new FinishedServiceOperationEventArgs(_currentOperation));
                }
            }

            catch (Exception e)
            {
                if ((e is ThreadAbortException) == false)
                {
                    if (ErrorOperation != null)
                    {
                        ErrorOperation(this, new ErrorServiceOperationEventArgs(_currentOperation, e));
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Starts the service.
        /// </summary>
        public void StartService()
        {
            if (ServiceController.GetServices().FirstOrDefault(s => s.ServiceName.Equals(ServiceName, StringComparison.OrdinalIgnoreCase)) == null)
            {
                return;
            }

            using (var serviceController = new ServiceController(this.ServiceName))
            {
                if (serviceController.Status == ServiceControllerStatus.PausePending)
                {
                    serviceController.WaitForStatus(ServiceControllerStatus.Paused, serviceControllerTimeout);
                }
                if (serviceController.Status == ServiceControllerStatus.Paused)
                {
                    serviceController.Continue();
                }

                if (serviceController.Status == ServiceControllerStatus.StopPending)
                {
                    serviceController.WaitForStatus(ServiceControllerStatus.Stopped, serviceControllerTimeout);
                }
                if (serviceController.Status == ServiceControllerStatus.Stopped)
                {
                    serviceController.Start();
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Waits for the service to reach the status of Started.
        /// </summary>
        /// <param name="timeout">The amount of time to wait for
        /// the service to reach the specified status.</param>
        public void WaitForStart(TimeSpan timeout)
        {
            switch (sc.Status)
            {
            case ServiceControllerStatus.Running:
                return;

            case ServiceControllerStatus.PausePending:
                sc.WaitForStatus(ServiceControllerStatus.Paused, timeout);
                goto case ServiceControllerStatus.Paused;

            case ServiceControllerStatus.Paused:
                sc.Continue();
                break;

            case ServiceControllerStatus.StopPending:
                sc.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
                goto case ServiceControllerStatus.Stopped;

            case ServiceControllerStatus.Stopped:
                sc.Start();
                break;
            }
            sc.WaitForStatus(ServiceControllerStatus.Running, timeout);
        }
コード例 #13
0
        private bool TryStop(ServiceController service)
        {
            var success = false;

            if (service.Status == ServiceControllerStatus.Paused)
            {
                service.Continue();
                service.Refresh();
            }

            if (service.Status == ServiceControllerStatus.StartPending || service.Status == ServiceControllerStatus.ContinuePending)
            {
                service.WaitForStatus(ServiceControllerStatus.Running, FIVE_SECONDS);
                service.Refresh();
            }

            if (service.Status == ServiceControllerStatus.Running)
            {
                service.Stop();
                service.Refresh();
            }

            if (service.Status == ServiceControllerStatus.StopPending)
            {
                service.WaitForStatus(ServiceControllerStatus.Stopped, FIVE_SECONDS);
                service.Refresh();
            }

            if (service.Status == ServiceControllerStatus.Stopped)
            {
                success = true;
            }

            return(success);
        }
コード例 #14
0
        public MainResult ContinueService()
        {
            bool   success = true;
            string error   = "";
            DataResult <ServiceController> dataResult = InitializeServiceController();

            if (dataResult.MainResult.Success)
            {
                ServiceController serviceController = dataResult.Data;

                try
                {
                    if (serviceController.Status == ServiceControllerStatus.Paused)
                    {
                        serviceController.Continue();
                        serviceController.WaitForStatus(ServiceControllerStatus.Running);
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    error   = $"An error occured while continuing the service. Error: {ex.Message}";
                }

                return(new MainResult
                {
                    Success = success,
                    ErrorMessage = error
                });
            }
            else
            {
                return(dataResult.MainResult);
            }
        }
コード例 #15
0
        private void btnContinuar_Click(object sender, EventArgs e)
        {
            ServiceController service = ObterServicoSelecionado();

            service.Continue();
            AtualizarServico(service);
        }
コード例 #16
0
        public void PauseAndContinue()
        {
            string serviceName = _testService.TestServiceName;
            var    controller  = new ServiceController(serviceName);

            controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

            using (var client = new NamedPipeClientStream(".", serviceName, PipeDirection.In))
            {
                client.Connect();
                for (int i = 0; i < 2; i++)
                {
                    controller.Pause();
                    client.ReadByte();
                    controller.WaitForStatus(ServiceControllerStatus.Paused, _testService.ControlTimeout);
                    Assert.Equal(ServiceControllerStatus.Paused, controller.Status);

                    controller.Continue();
                    client.ReadByte();
                    controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
                    Assert.Equal(ServiceControllerStatus.Running, controller.Status);
                }
            }
        }
コード例 #17
0
ファイル: ServiceUtil.cs プロジェクト: muhliz25/cs-codebook
        /* Methode zum Fortfahren eines Dienstes */
        public static ServiceControllerStatus ContinueService(string serviceName,
                                                              string machineName, int timeout)
        {
            // Dienst ermitteln
            if (machineName == null)
            {
                machineName = ".";
            }
            ServiceController service = new ServiceController(
                serviceName, machineName);

            // Überprüfen, ob der Dienst fortgefahren werden kann
            if (service.CanPauseAndContinue == false)
            {
                throw new Exception("Der Dienst '" + serviceName +
                                    "' kann nicht fortgefahren werden");
            }

            // Dienst fortfahren, falls dieser nicht bereits ausgeführt wird
            // oder gerade startet
            if (service.Status != ServiceControllerStatus.Running &&
                service.Status != ServiceControllerStatus.StartPending &&
                service.Status != ServiceControllerStatus.ContinuePending)
            {
                service.Continue();
            }

            // Den übergebenen Timeout (in Millisekunden) warten, bis der Dienst den
            // Status Running besitzt
            service.WaitForStatus(ServiceControllerStatus.Running,
                                  new TimeSpan(0, 0, 0, timeout));

            // Status des Dienstes zurückliefern
            return(service.Status);
        }
コード例 #18
0
ファイル: ClServCtl.cs プロジェクト: leonchen09/poc
 /// <summary>
 /// 恢复暂停的服务
 /// </summary>
 /// <param name="servername"></param>
 /// <returns></returns>
 public static bool ResumeService(string servername)
 {
     try
     {
         ServiceController       sc = new ServiceController(servername);
         ServiceControllerStatus st = sc.Status;
         switch (st)
         {
         case ServiceControllerStatus.Paused:
         case ServiceControllerStatus.PausePending:
             sc.Continue();
             sc.WaitForStatus(ServiceControllerStatus.Running);
             break;
         }
         st = sc.Status;//再次获取服务状态
         if (st == ServiceControllerStatus.Running)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch { return(false); }
 }
コード例 #19
0
 public string ContinueService()
 {
     try
     {
         ServiceController sc = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName.Equals(serviceName));
         if (sc != null)
         {
             if (sc.Status == ServiceControllerStatus.Paused)
             {
                 sc.Continue();
                 return("Resumed");
             }
             else
             {
                 return("Service not paused");
             }
         }
         else
         {
             return("Service not found");
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
コード例 #20
0
        private static bool StartService(string serviceName, int timeoutMilliseconds)
        {
            var service = new ServiceController(serviceName);

            try
            {
                var timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

                //If paused then Continue the service, do not attempt to start.
                if (service.Status.Equals(ServiceControllerStatus.Paused))
                {
                    service.Continue();
                    service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                    if (service.Status.Equals(ServiceControllerStatus.Running))
                    {
                        return(true);
                    }
                    return(false);
                }

                //Service is not Paused, Start it.
                service.Start();
                service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                if (service.Status.Equals(ServiceControllerStatus.Running))
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
                return(false);
            }
        }
コード例 #21
0
        protected void buttonCommand_Click(object sender, System.EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            ServiceController controller = (ServiceController)listBoxServices.SelectedItem;

            if (sender == this.buttonStart)
            {
                controller.Start();
                controller.WaitForStatus(ServiceControllerStatus.Running);
            }
            else if (sender == this.buttonStop)
            {
                controller.Stop();
                controller.WaitForStatus(ServiceControllerStatus.Stopped);
            }
            else if (sender == this.buttonPause)
            {
                controller.Pause();
                controller.WaitForStatus(ServiceControllerStatus.Paused);
            }
            else if (sender == this.buttonContinue)
            {
                controller.Continue();
                controller.WaitForStatus(ServiceControllerStatus.Running);
            }

            int index = listBoxServices.SelectedIndex;

            RefreshServiceList();
            listBoxServices.SelectedIndex = index;
            Cursor.Current = Cursors.Default;
        }
コード例 #22
0
        private void btn_resume_Click(object sender, EventArgs e)
        {
            ServiceController sr = new ServiceController(selectedService);

            sr.Continue();
            updateApplications();
        }
コード例 #23
0
        public void PauseAndContinue()
        {
            string serviceName = _testService.TestServiceName;
            var    controller  = new ServiceController(serviceName);

            controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

            _testService.Client.Connect(connectionTimeout);
            Assert.Equal((int)PipeMessageByteCode.Connected, _testService.GetByte());

            for (int i = 0; i < 2; i++)
            {
                controller.Pause();
                Assert.Equal((int)PipeMessageByteCode.Pause, _testService.GetByte());
                controller.WaitForStatus(ServiceControllerStatus.Paused, _testService.ControlTimeout);
                Assert.Equal(ServiceControllerStatus.Paused, controller.Status);

                controller.Continue();
                Assert.Equal((int)PipeMessageByteCode.Continue, _testService.GetByte());
                controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
                Assert.Equal(ServiceControllerStatus.Running, controller.Status);
            }

            controller.Stop();
            Assert.Equal((int)PipeMessageByteCode.Stop, _testService.GetByte());
            controller.WaitForStatus(ServiceControllerStatus.Stopped, _testService.ControlTimeout);
            Assert.Equal(ServiceControllerStatus.Stopped, controller.Status);
        }
コード例 #24
0
        public static string Pause(string serviceName)
        {
            ServiceController serviceController = new ServiceController(serviceName);

            if (serviceController.CanPauseAndContinue)
            {
                if (serviceController.Status == ServiceControllerStatus.Running)
                {
                    serviceController.Pause();
                    return("Paused");
                }
                else if (serviceController.Status == ServiceControllerStatus.Paused)
                {
                    serviceController.Continue();
                    return("Resume");
                }
                else
                {
                    return("Stopped");
                }
            }
            else
            {
                return("Can't pause an continue");
            }
        }
コード例 #25
0
        private void btnPauseContinue_Click(object sender, RoutedEventArgs e)
        {
            ServiceController serviceController = new ServiceController("ServiceHr");

            if (serviceController.CanPauseAndContinue)
            {
                if (serviceController.Status == ServiceControllerStatus.Running)
                {
                    serviceController.Pause();
                    lblStatus.Text = "服务已暂停";
                }
                else if (serviceController.Status == ServiceControllerStatus.Paused)
                {
                    serviceController.Continue();
                    lblStatus.Text = "服务已继续";
                }
                else
                {
                    lblStatus.Text = "服务未处于暂停和启动状态";
                }
            }
            else
            {
                lblStatus.Text = "服务不能暂停";
            }
        }
コード例 #26
0
 public void Continue()
 {
     using (var sc = new ServiceController(Name))
     {
         sc.Continue();
     }
 }
コード例 #27
0
        private void StartService(string name)
        {
            using (var SrvCtl = new ServiceController(name))
            {
                switch (SrvCtl.Status)
                {
                case ServiceControllerStatus.ContinuePending:
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Running, ServiceTimeout);
                    break;

                case ServiceControllerStatus.Paused:
                    SrvCtl.Continue();
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Running, ServiceTimeout);
                    break;

                case ServiceControllerStatus.PausePending:
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Paused, ServiceTimeout);
                    SrvCtl.Continue();
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Running, ServiceTimeout);
                    break;

                case ServiceControllerStatus.Running: break;

                case ServiceControllerStatus.StartPending:
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Running, ServiceTimeout);
                    break;

                case ServiceControllerStatus.Stopped:
                    SrvCtl.Start();
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Running, ServiceTimeout);
                    break;

                case ServiceControllerStatus.StopPending:
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Stopped, ServiceTimeout);
                    SrvCtl.Start();
                    SrvCtl.WaitForStatus(ServiceControllerStatus.Running, ServiceTimeout);
                    break;
                }
                if (SrvCtl.Status != ServiceControllerStatus.Running)
                {
                    throw new Exception("启动服务" + SrvCtl.ServiceName + "失败");
                }
            }
        }
コード例 #28
0
        internal bool DoResumeService(ServiceController serviceController)
        {
            Exception exception = null;
            bool      flag      = false;

            try
            {
                serviceController.Continue();
            }
            catch (Win32Exception win32Exception1)
            {
                Win32Exception win32Exception = win32Exception1;
                if (0x426 == win32Exception.NativeErrorCode)
                {
                    flag = true;
                }
                exception = win32Exception;
            }
            catch (InvalidOperationException invalidOperationException1)
            {
                InvalidOperationException invalidOperationException = invalidOperationException1;
                Win32Exception            innerException            = invalidOperationException.InnerException as Win32Exception;
                if (innerException != null && 0x426 == innerException.NativeErrorCode)
                {
                    flag = true;
                }
                exception = invalidOperationException;
            }
            if (exception == null)
            {
                if (this.DoWaitForStatus(serviceController, ServiceControllerStatus.Running, ServiceControllerStatus.ContinuePending, ServiceResources.ResumingService, "ResumeServiceFailed", ServiceResources.ResumeServiceFailed))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (!flag)
                {
                    if (!serviceController.CanPauseAndContinue)
                    {
                        base.WriteNonTerminatingError(serviceController, exception, "CouldNotResumeServiceNotSupported", ServiceResources.CouldNotResumeServiceNotSupported, ErrorCategory.CloseError);
                    }
                }
                else
                {
                    base.WriteNonTerminatingError(serviceController, exception, "CouldNotResumeServiceNotRunning", ServiceResources.CouldNotResumeServiceNotRunning, ErrorCategory.CloseError);
                }
                base.WriteNonTerminatingError(serviceController, exception, "CouldNotResumeService", ServiceResources.CouldNotResumeService, ErrorCategory.CloseError);
                return(false);
            }
        }
コード例 #29
0
ファイル: ServiceUtil.cs プロジェクト: formist/LinkMe
        public static void Continue(string computer, string service, bool wait, System.TimeSpan timeout)
        {
            var controller = new ServiceController(service, computer);

            controller.Continue();
            if (wait)
            {
                controller.WaitForStatus(ServiceControllerStatus.Running, timeout);
            }
        }
コード例 #30
0
ファイル: ServiceBaseTests.cs プロジェクト: kayjtea/runtime
        public void TestOnContinueBeforePause()
        {
            ServiceController controller = ConnectToServer();

            controller.Continue();
            controller.WaitForStatus(ServiceControllerStatus.Running);

            controller.Stop();
            Assert.Equal((int)PipeMessageByteCode.Stop, _testService.GetByte());
            controller.WaitForStatus(ServiceControllerStatus.Stopped);
        }
コード例 #31
0
        public void PauseAndContinue()
        {
            var controller = new ServiceController(_testService.TestServiceName);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

            for (int i = 0; i < 2; i++)
            {
                controller.Pause();
                controller.WaitForStatus(ServiceControllerStatus.Paused, _testService.ControlTimeout);
                Assert.Equal(ServiceControllerStatus.Paused, controller.Status);

                controller.Continue();
                controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
                Assert.Equal(ServiceControllerStatus.Running, controller.Status);
            }
        }
コード例 #32
0
ファイル: ServiceManager.cs プロジェクト: haikavn/x.stat
    /// <summary>
    /// Continues the service.
    /// </summary>
    /// <param name="serviceName">Name of the service.</param>
    /// <returns></returns>
    public static bool ContinueService(string serviceName)
    {
        using (ServiceController sc = new ServiceController(serviceName))
        {
            if (sc.CanPauseAndContinue)
            {
                sc.Continue();

                while (sc.Status != ServiceControllerStatus.ContinuePending)
                {
                    Thread.Sleep(1000);
                    sc.Refresh();
                }

                if (sc.Status == ServiceControllerStatus.Running)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        return false;
    }