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


C# ServiceController.WaitForStatus方法代码示例

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


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

示例1: WaitForStatusTimeout

 public void WaitForStatusTimeout()
 {
     var controller = new ServiceController(_testService.TestServiceName);
     Assert.Throws<System.ServiceProcess.TimeoutException>(() => controller.WaitForStatus(ServiceControllerStatus.Paused, TimeSpan.Zero));
 }
开发者ID:rendle-labs,项目名称:corefx,代码行数:5,代码来源:ServiceControllerTests.cs

示例2: StopAndStart

        public void StopAndStart()
        {
            var controller = new ServiceController(_testService.TestServiceName);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

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

                controller.Start();
                controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
                Assert.Equal(ServiceControllerStatus.Running, controller.Status);
            }
        }
开发者ID:rendle-labs,项目名称:corefx,代码行数:16,代码来源:ServiceControllerTests.cs

示例3: PauseAndContinue

        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);
            }
        }
开发者ID:rendle-labs,项目名称:corefx,代码行数:16,代码来源:ServiceControllerTests.cs

示例4: StartWithArguments

        public void StartWithArguments()
        {
            var controller = new ServiceController(_testService.TestServiceName);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

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

            var args = new[] { "a", "b", "c", "d", "e" };
            controller.Start(args);
            controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);
            Assert.Equal(ServiceControllerStatus.Running, controller.Status);

            // The test service writes the arguments that it was started with to the _testService.TestServiceRegistryKey.
            // Read this key to verify that the arguments were properly passed to the service.
            string argsString = Registry.GetValue(_testService.TestServiceRegistryKey, "ServiceArguments", null) as string;
            Assert.Equal(string.Join(",", args), argsString);
        }
开发者ID:rendle-labs,项目名称:corefx,代码行数:19,代码来源:ServiceControllerTests.cs

示例5: Main


//.........这里部分代码省略.........
            {
              Log.Debug("Main: Failed to retrieve TV service status");
              ctrl.Close();
              ctrl = null;
            }
          }

          if (ctrl != null)
          {
            Log.Debug("Main: TV service found. Checking status...");
            UpdateSplashScreenMessage(GUILocalizeStrings.Get(60)); // Waiting for startup of TV service...
            if (ctrl.Status == ServiceControllerStatus.StartPending || ctrl.Status == ServiceControllerStatus.Stopped)
            {
              if (ctrl.Status == ServiceControllerStatus.StartPending)
              {
                Log.Info("Main: TV service start is pending. Waiting...");
              }

              if (ctrl.Status == ServiceControllerStatus.Stopped)
              {
                Log.Info("Main: TV service is stopped, so we try start it...");
                try
                {
                  ctrl.Start();
                }
                catch (Exception)
                {
                  Log.Info("TvService seems to be already starting up.");
                }
              }

              try
              {
                ctrl.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 45));
              }
              // ReSharper disable EmptyGeneralCatchClause
              catch (Exception) {}
              // ReSharper restore EmptyGeneralCatchClause
              
              if (ctrl.Status == ServiceControllerStatus.Running)
              {
                Log.Info("Main: The TV service has started successfully.");
              }
              else
              {
                Log.Info("Main: Startup of the TV service failed - current status: {0}", ctrl.Status.ToString());
              }
            }
            Log.Info("Main: TV service is in status {0} - proceeding...", ctrl.Status.ToString());
            ctrl.Close();
          }
        }

        Application.DoEvents(); // process message queue

        if (_startupDelay > 0)
        {
          Log.Info("Main: Waiting {0} second(s) before startup", _startupDelay);
          for (int i = _startupDelay; i > 0; i--)
          {
            UpdateSplashScreenMessage(String.Format(GUILocalizeStrings.Get(61), i.ToString(CultureInfo.InvariantCulture)));
            Thread.Sleep(1000);
            Application.DoEvents();
          }
        }
开发者ID:GhoSe-OSS,项目名称:MonoTV,代码行数:66,代码来源:MediaPortal.cs

示例6: Main


//.........这里部分代码省略.........
          }
          catch (Exception)
          {
            ctrl = null;
            Log.Debug("Main: TV service not installed - proceeding...");
          }
          if (ctrl != null)
          {
            Log.Debug("Main: TV service found. Checking status...");
            if (splashScreen != null)
            {
              splashScreen.SetInformation(GUILocalizeStrings.Get(60)); // Waiting for startup of TV service...
            }
            if (ctrl.Status == ServiceControllerStatus.StartPending || ctrl.Status == ServiceControllerStatus.Stopped)
            {
              if (ctrl.Status == ServiceControllerStatus.StartPending)
              {
                Log.Info("Main: TV service start is pending. Waiting...");
              }
              if (ctrl.Status == ServiceControllerStatus.Stopped)
              {
                Log.Info("Main: TV service is stopped, so we try start it...");
                try
                {
                  ctrl.Start();
                }
                catch (Exception)
                {
                  Log.Info("TvService seems to be already starting up.");
                }
              }
              try
              {
                ctrl.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 45));
              }
              catch (Exception) {}
              if (ctrl.Status == ServiceControllerStatus.Running)
              {
                Log.Info("Main: The TV service has started successfully.");
              }
              else
              {
                Log.Info("Main: Startup of the TV service failed - current status: {0}", ctrl.Status.ToString());
              }
            }
            Log.Info("Main: TV service is in status {0} - proceeding...", ctrl.Status.ToString());
            ctrl.Close();
          }
        }
        Application.DoEvents();
        if (_startupDelay > 0)
        {
          Log.Info("Main: Waiting {0} second(s) before startup", _startupDelay);
          for (int i = _startupDelay; i > 0; i--)
          {
            if (splashScreen != null)
            {
              splashScreen.SetInformation(String.Format(GUILocalizeStrings.Get(61), i.ToString()));
              // Waiting {0} second(s) before startup...
            }
            Application.DoEvents();
            Thread.Sleep(1000);
          }
        }
        Log.Debug("Main: Checking prerequisites");
        try
开发者ID:nio22,项目名称:MediaPortal-1,代码行数:67,代码来源:MediaPortal.cs

示例7: RestartC2RSerivce

 public static void RestartC2RSerivce()
 {
     const string serviceName = "ClickToRunSvc";
     var service = new ServiceController(serviceName);
     service.Stop();
     service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 5));
     service.Start();
     service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 5));
 }
开发者ID:OfficeDev,项目名称:Office-IT-Pro-Deployment-Scripts,代码行数:9,代码来源:InstallOffice.cs

示例8: ControlCapabilities

        public void ControlCapabilities()
        {
            var controller = new ServiceController(_testService.TestServiceName);
            controller.WaitForStatus(ServiceControllerStatus.Running, _testService.ControlTimeout);

            Assert.True(controller.CanStop);
            Assert.True(controller.CanPauseAndContinue);
            Assert.False(controller.CanShutdown);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:ServiceControllerTests.cs


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