本文整理汇总了C#中ServiceController.Pause方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceController.Pause方法的具体用法?C# ServiceController.Pause怎么用?C# ServiceController.Pause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceController
的用法示例。
在下文中一共展示了ServiceController.Pause方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: PauseService
/// <summary>
/// Pauses the service.
/// </summary>
/// <param name="serviceName">Name of the service.</param>
/// <returns></returns>
public static bool PauseService(string serviceName)
{
using (ServiceController sc = new ServiceController(serviceName))
{
if (sc.CanPauseAndContinue)
{
sc.Pause();
while (sc.Status != ServiceControllerStatus.Paused)
{
Thread.Sleep(1000);
sc.Refresh();
}
if (sc.Status == ServiceControllerStatus.Paused)
{
return true;
}
else
{
return false;
}
}
}
return false;
}