当前位置: 首页>>代码示例>>C#>>正文


C# ServiceController.Continue方法代码示例

本文整理汇总了C#中System.ServiceProcess.ServiceController.Continue方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceController.Continue方法的具体用法?C# ServiceController.Continue怎么用?C# ServiceController.Continue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceProcess.ServiceController的用法示例。


在下文中一共展示了ServiceController.Continue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartService

        /// <summary>
        /// Start the service with the given name and wait until the status of the service is running.
        /// If the service status is not running after the given timeout then the service is considered not started.
        /// You can call this method after stop or pause the service in order to re-start it.
        /// </summary>
        /// <param name="serviceName">The name of the service</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>True if the service has been started. Otherwise, false.</returns>
        public static bool StartService(string serviceName, TimeSpan timeout)
        {
            try
            {
                bool timeoutEnabled = (timeout.CompareTo(TimeSpan.Zero) > 0);
                using (ServiceController c = new ServiceController(serviceName))
                {
                    c.Refresh();
                    if (timeoutEnabled && c.Status == ServiceControllerStatus.Running)
                        return true;
                    if (!timeoutEnabled && (c.Status == ServiceControllerStatus.Running || c.Status == ServiceControllerStatus.StartPending || c.Status == ServiceControllerStatus.ContinuePending))
                        return true;

                    if (c.Status == ServiceControllerStatus.Paused || c.Status == ServiceControllerStatus.ContinuePending)
                        c.Continue();
                    else if (c.Status == ServiceControllerStatus.Stopped || c.Status == ServiceControllerStatus.StartPending)
                        c.Start();
                    if (timeoutEnabled)
                        c.WaitForStatus(ServiceControllerStatus.Running, timeout);
                    return true;
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error starting service {0}.", serviceName);
                return false;
            }
        }
开发者ID:OPCFoundation,项目名称:UA-.NET,代码行数:36,代码来源:ServiceManager.cs

示例2: btnPauseContinue_Click

 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));
     }
 }
开发者ID:shakasi,项目名称:shakasi.github.com,代码行数:33,代码来源:WindowsServiceManageFrm.cs

示例3: btnPauseContinue_Click

        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)
            {

            }
        }
开发者ID:shakasi,项目名称:shakasi.github.com,代码行数:32,代码来源:WindowsServiceManageFrm.cs

示例4: btnPause_Click

 private void btnPause_Click(object sender, RoutedEventArgs e)
 {
     ServiceController serviceController = new ServiceController("ApolloOaService");
     if (serviceController.CanPauseAndContinue)
     {
         if (serviceController.Status == ServiceControllerStatus.Running)
         {
             serviceController.Pause();
             lblMessages.Content = "服务已暂停.";
         }
         else if (serviceController.Status == ServiceControllerStatus.Paused)
         {
             serviceController.Continue();
             lblMessages.Content = "服务已恢复.";
         }
     }
 }
开发者ID:IvanYang,项目名称:ApolloOa2011,代码行数:17,代码来源:MainWindow.xaml.cs

示例5: ContinueService

        public static void ContinueService(string serviceName, int timeoutMilliseconds)
        {
            ServiceController service = new ServiceController(serviceName);
            try
            {
                if (service.Status == ServiceControllerStatus.Paused)
                {
                    TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

                    service.Continue();
                    service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                }
            }
            catch
            {
                throw;
            }
        }
开发者ID:akretion,项目名称:uninfe,代码行数:18,代码来源:ServiceProcess.cs

示例6: btnPauseContinue_Click

 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 = "服务不能暂停";
 }
开发者ID:TGHGH,项目名称:MesDemo,代码行数:23,代码来源:MainWindow.xaml.cs

示例7: Continue_ServiceName_Empty

		public void Continue_ServiceName_Empty ()
		{
			ServiceController sc = new ServiceController ();
			try {
				sc.Continue ();
				Assert.Fail ("#1");
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
				Assert.IsNotNull (ex.Message, "#3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#5");
				Assert.IsNull (ex.ParamName, "#6");
				Assert.IsNull (ex.InnerException, "#7");
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:ServiceControllerTest.cs

示例8: Continue_Service_Running

		public void Continue_Service_Running ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc1 = new ServiceController ("Schedule", ".");
			ServiceController sc2 = new ServiceController ("Schedule", ".");

			Assert.AreEqual (ServiceControllerStatus.Running, sc1.Status, "#A1");
			Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#A2");

			sc1.Continue ();

			Assert.AreEqual (ServiceControllerStatus.Running, sc1.Status, "#B1");
			Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#B2");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:ServiceControllerTest.cs

示例9: Continue_Service_Stopped

		public void Continue_Service_Stopped ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc1 = new ServiceController ("Schedule", ".");
			ServiceController sc2 = new ServiceController ("Schedule", ".");

			Assert.AreEqual (ServiceControllerStatus.Running, sc1.Status, "#A1");
			Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#A2");

			sc1.Stop ();

			try {
				Assert.AreEqual (ServiceControllerStatus.Running, sc1.Status, "#B1");
				Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#B2");

				sc1.WaitForStatus (ServiceControllerStatus.Stopped, new TimeSpan (0, 0, 5));

				Assert.AreEqual (ServiceControllerStatus.Stopped, sc1.Status, "#C1");
				Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#C2");

				sc1.Continue ();
				Assert.Fail ("#D1");
			} catch (InvalidOperationException ex) {
				// Cannot resume Schedule service on computer '.'
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
				Assert.IsNotNull (ex.Message, "#D3");
				Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#D4");
				Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#D5");
				Assert.IsNotNull (ex.InnerException, "#D6");

				// The service has not been started
				Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#D7");
				Win32Exception win32Error = (Win32Exception) ex.InnerException;
				//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#D8");
				Assert.IsNotNull (win32Error.Message, "#D9");
				Assert.AreEqual (1062, win32Error.NativeErrorCode, "#D10");
				Assert.IsNull (win32Error.InnerException, "#D11");
			} finally {
				EnsureServiceIsRunning (sc1);
				sc2.Refresh ();
			}

			Assert.AreEqual (ServiceControllerStatus.Running, sc1.Status, "#E1");
			Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#E2");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:47,代码来源:ServiceControllerTest.cs

示例10: ContinueService

        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;
            }
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:41,代码来源:Controller.cs

示例11: Continue_Service_OperationNotValid

		public void Continue_Service_OperationNotValid ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc1 = new ServiceController ("SamSs", ".");
			ServiceController sc2 = new ServiceController ("SamSs", ".");

			Assert.AreEqual (ServiceControllerStatus.Running, sc1.Status, "#A1");
			Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#A2");

			try {
				sc1.Continue ();
				Assert.Fail ("#B1");
			} catch (InvalidOperationException ex) {
				// Cannot resume SamSs service on computer '.'
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
				Assert.IsNotNull (ex.Message, "#B3");
				Assert.IsTrue (ex.Message.IndexOf ("SamSs") != -1, "#B4");
				Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#B5");
				Assert.IsNotNull (ex.InnerException, "#B6");

				// The requested control is not valid for this service
				Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#B7");
				Win32Exception win32Error = (Win32Exception) ex.InnerException;
				//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#B8");
				Assert.IsNotNull (win32Error.Message, "#B9");
				Assert.AreEqual (1052, win32Error.NativeErrorCode, "#B10");
				Assert.IsNull (win32Error.InnerException, "#B11");
			}

			Assert.AreEqual (ServiceControllerStatus.Running, sc1.Status, "#C1");
			Assert.AreEqual (ServiceControllerStatus.Running, sc2.Status, "#C2");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:34,代码来源:ServiceControllerTest.cs

示例12: btnResume_Click

        private void btnResume_Click(object sender, EventArgs e)
        {
            ServiceController sc = new ServiceController(serviceName);
            if (sc != null)
            {
                sc.Continue();
                sc.WaitForStatus(ServiceControllerStatus.Running);
            }
			 _parentDlg.commit = true;
            SetData();
        }
开发者ID:FarazShaikh,项目名称:likewise-open,代码行数:11,代码来源:GeneralPropertyPage.cs

示例13: ContinueService

        private bool ContinueService(Service serviceController)
        {
            if (serviceController.Status == ServiceControllerStatus.Running)
            {
                return true; // already running
            }

            if (!serviceController.CanPauseAndContinue)
            {
                Log.LogError(Properties.Resources.ServiceCannotContinue,
                    ServiceName, MachineName);
                return false;
            }
            if (serviceController.Status != ServiceControllerStatus.Paused)
            {
                Log.LogError(Properties.Resources.ServiceNotPaused,
                    ServiceName, MachineName);
                return false;
            }

            Log.LogMessage(Properties.Resources.ServiceContinuing, DisplayName);

            serviceController.Continue();

            // wait until service is running or timeout expired
            serviceController.WaitForStatus(ServiceControllerStatus.Running,
                TimeSpan.FromMilliseconds(Timeout));

            Log.LogMessage(Properties.Resources.ServiceContinued, DisplayName);

            return true;
        }
开发者ID:trippleflux,项目名称:jezatools,代码行数:32,代码来源:ServiceController.cs

示例14: Constructor1

		public void Constructor1 ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc = new ServiceController ();

			try {
				bool value = sc.CanPauseAndContinue;
				Assert.Fail ("#A1: " + value.ToString ());
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
				Assert.IsNotNull (ex.Message, "#A3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#A4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#A5");
				Assert.IsNull (ex.ParamName, "#A6");
				Assert.IsNull (ex.InnerException, "#A7");
			}

			try {
				bool value = sc.CanShutdown;
				Assert.Fail ("#B1: " + value.ToString ());
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
				Assert.IsNotNull (ex.Message, "#B3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#B4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#B5");
				Assert.IsNull (ex.ParamName, "#B6");
				Assert.IsNull (ex.InnerException, "#B7");
			}

			try {
				bool value = sc.CanStop;
				Assert.Fail ("#C1: " + value.ToString ());
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
				Assert.IsNotNull (ex.Message, "#C3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#C4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#C5");
				Assert.IsNull (ex.ParamName, "#C6");
				Assert.IsNull (ex.InnerException, "#C7");
			}

			// closing the ServiceController does not result in exception
			sc.Close ();

			try {
				sc.Continue ();
				Assert.Fail ("#D1");
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
				Assert.IsNotNull (ex.Message, "#D3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#D4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#D5");
				Assert.IsNull (ex.ParamName, "#D6");
				Assert.IsNull (ex.InnerException, "#D7");
			}

			try {
				Assert.Fail ("#E1: " + sc.DependentServices.Length);
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
				Assert.IsNotNull (ex.Message, "#E3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#E4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#E5");
				Assert.IsNull (ex.ParamName, "#E6");
				Assert.IsNull (ex.InnerException, "#E7");
			}

			Assert.IsNotNull (sc.DisplayName, "#F1");
			Assert.AreEqual (string.Empty, sc.DisplayName, "#F2");

			try {
				sc.ExecuteCommand (0);
				Assert.Fail ("#G1");
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#G2");
				Assert.IsNotNull (ex.Message, "#G3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#G4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#G5");
				Assert.IsNull (ex.ParamName, "#G6");
				Assert.IsNull (ex.InnerException, "#G7");
			}

			Assert.IsNotNull (sc.MachineName, "#H1");
			Assert.AreEqual (".", sc.MachineName, "#H2");


//.........这里部分代码省略.........
开发者ID:nlhepler,项目名称:mono,代码行数:101,代码来源:ServiceControllerTest.cs

示例15: Main

        static void Main(string[] args)
        {
            ServiceController[] scServices;
            scServices = ServiceController.GetServices();

            foreach (ServiceController scTemp in scServices)
            {

                if (scTemp.ServiceName == "Simple Service")
                {
                    // Display properties for the Simple Service sample
                    // from the ServiceBase example.
                    ServiceController sc = new ServiceController("Simple Service");
                    Console.WriteLine("Status = " + sc.Status);
                    Console.WriteLine("Can Pause and Continue = " + sc.CanPauseAndContinue);
                    Console.WriteLine("Can ShutDown = " + sc.CanShutdown);
                    Console.WriteLine("Can Stop = " + sc.CanStop);
                    if (sc.Status == ServiceControllerStatus.Stopped)
                    {
                        sc.Start();
                        while (sc.Status == ServiceControllerStatus.Stopped)
                        {
                            Thread.Sleep(1000);
                            sc.Refresh();
                        }
                    }
                    // Issue custom commands to the service
                    // enum SimpleServiceCustomCommands
                    //    { StopWorker = 128, RestartWorker, CheckWorker };
                    sc.ExecuteCommand((int)SimpleServiceCustomCommands.StopWorker);
                    sc.ExecuteCommand((int)SimpleServiceCustomCommands.RestartWorker);
                    sc.Pause();
                    while (sc.Status != ServiceControllerStatus.Paused)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    sc.Continue();
                    while (sc.Status == ServiceControllerStatus.Paused)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    sc.Stop();
                    while (sc.Status != ServiceControllerStatus.Stopped)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    String[] argArray = new string[] { "ServiceController arg1", "ServiceController arg2" };
                    sc.Start(argArray);
                    while (sc.Status == ServiceControllerStatus.Stopped)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    // Display the event log entries for the custom commands
                    // and the start arguments.
                    EventLog el = new EventLog("Application");
                    EventLogEntryCollection elec = el.Entries;
                    foreach (EventLogEntry ele in elec)
                    {
                        if (ele.Source.IndexOf("SimpleService.OnCustomCommand") >= 0 |
                            ele.Source.IndexOf("SimpleService.Arguments") >= 0)
                            Console.WriteLine(ele.Message);
                    }
                }
            }
            Console.ReadKey();
        }
开发者ID:eandbsoftware,项目名称:MCTS_70_536_AllQuestions,代码行数:74,代码来源:Program.cs


注:本文中的System.ServiceProcess.ServiceController.Continue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。