ServiceController.Pause 方法

定义

挂起服务的操作。Suspends a service's operation.

public:
 void Pause();
public void Pause ();
member this.Pause : unit -> unit
Public Sub Pause ()

例外

访问 API 时出错。An error occurred when accessing a system API.

未找到服务。The service was not found.

示例

下面的示例演示如何使用 Pause 方法暂停服务。The following example demonstrates the use of the Pause method to pause a service. 此示例是为类提供的更大示例的一部分 ServiceControllerThis example is part of a larger example that is provided for the ServiceController class.

sc.Pause();
while (sc.Status != ServiceControllerStatus.Paused)
{
    Thread.Sleep(1000);
    sc.Refresh();
}
Console.WriteLine("Status = " + sc.Status);
sc.Pause()
While sc.Status <> ServiceControllerStatus.Paused
    Thread.Sleep(1000)
    sc.Refresh()
End While
Console.WriteLine("Status = " + sc.Status.ToString())

注解

Continue 服务控制器状态为之前,你无法调用服务 PausedYou cannot call Continue for the service until the service controller status is Paused.

适用于

另请参阅