ServiceController.WaitForStatus 메서드

정의

서비스가 지정된 상태에 도달할 때까지 대기합니다.

오버로드

WaitForStatus(ServiceControllerStatus)

서비스가 지정된 상태에 도달할 때까지 무제한 대기합니다.

WaitForStatus(ServiceControllerStatus, TimeSpan)

서비스가 지정된 상태에 도달하거나 지정된 제한 시간이 만료될 때까지 대기합니다.

WaitForStatus(ServiceControllerStatus)

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

서비스가 지정된 상태에 도달할 때까지 무제한 대기합니다.

public:
 void WaitForStatus(System::ServiceProcess::ServiceControllerStatus desiredStatus);
public void WaitForStatus (System.ServiceProcess.ServiceControllerStatus desiredStatus);
member this.WaitForStatus : System.ServiceProcess.ServiceControllerStatus -> unit
Public Sub WaitForStatus (desiredStatus As ServiceControllerStatus)

매개 변수

desiredStatus
ServiceControllerStatus

대기할 상태입니다.

예외

desiredStatus 매개 변수가 ServiceControllerStatus 열거형에 정의된 값 중 하나가 아닌 경우

예제

다음 예제에서는 클래스를 ServiceController 사용하여 Alerter 서비스가 중지되었는지 여부를 확인합니다. 서비스가 중지되면 이 예제에서는 서비스를 시작하고 서비스 상태가 로 설정 Running될 때까지 기다립니다.

// Check whether the Alerter service is started.
ServiceController^ sc = gcnew ServiceController;
if ( sc )
{
   sc->ServiceName =  "Alerter";
   Console::WriteLine(  "The Alerter service status is currently set to {0}", sc->Status );
   if ( sc->Status == (ServiceControllerStatus::Stopped) )
   {
      // Start the service if the current status is stopped.
      Console::WriteLine(  "Starting the Alerter service..." );
      try
      {
         // Start the service, and wait until its status is "Running".
         sc->Start();
         sc->WaitForStatus( ServiceControllerStatus::Running );
         
         // Display the current service status.
         Console::WriteLine(  "The Alerter service status is now set to {0}.", sc->Status );
      }
      catch ( InvalidOperationException^ e ) 
      {
         Console::WriteLine(  "Could not start the Alerter service." );
      }
   }
}

// Check whether the Alerter service is started.

ServiceController sc  = new ServiceController();
sc.ServiceName = "Alerter";
Console.WriteLine("The Alerter service status is currently set to {0}",
                   sc.Status);

if (sc.Status == ServiceControllerStatus.Stopped)
{
   // Start the service if the current status is stopped.

   Console.WriteLine("Starting the Alerter service...");
   try
   {
      // Start the service, and wait until its status is "Running".
      sc.Start();
      sc.WaitForStatus(ServiceControllerStatus.Running);

      // Display the current service status.
      Console.WriteLine("The Alerter service status is now set to {0}.",
                         sc.Status);
   }
   catch (InvalidOperationException)
   {
      Console.WriteLine("Could not start the Alerter service.");
   }
}

' Check whether the Alerter service is started.

Dim sc As New ServiceController()
sc.ServiceName = "Alerter"
Console.WriteLine("The Alerter service status is currently set to {0}", sc.Status)

If sc.Status = ServiceControllerStatus.Stopped Then
   ' Start the service if the current status is stopped.
   Console.WriteLine("Starting the Alerter service...")

   Try
      ' Start the service, and wait until its status is "Running".
      sc.Start()
      sc.WaitForStatus(ServiceControllerStatus.Running)
      
      ' Display the current service status.
      Console.WriteLine("The Alerter service status is now set to {0}.", sc.Status)
   Catch 
      Console.WriteLine("Could not start the Alerter service.")
   End Try
End If

설명

사용 하 여 WaitForStatus 서비스 필요 상태에 도달한 때까지 처리의 애플리케이션을 일시 중단 합니다.

참고

메서드는 WaitForStatus 각 상태 검사 사이에 약 250밀리초를 대기합니다. WaitForStatus 는 관찰된 서비스가 로 변경된 후 해당 간격의 다른 상태로 즉시 변경 desiredStatus 되는 경우를 감지할 수 없습니다.

추가 정보

적용 대상

WaitForStatus(ServiceControllerStatus, TimeSpan)

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

서비스가 지정된 상태에 도달하거나 지정된 제한 시간이 만료될 때까지 대기합니다.

public:
 void WaitForStatus(System::ServiceProcess::ServiceControllerStatus desiredStatus, TimeSpan timeout);
public void WaitForStatus (System.ServiceProcess.ServiceControllerStatus desiredStatus, TimeSpan timeout);
member this.WaitForStatus : System.ServiceProcess.ServiceControllerStatus * TimeSpan -> unit
Public Sub WaitForStatus (desiredStatus As ServiceControllerStatus, timeout As TimeSpan)

매개 변수

desiredStatus
ServiceControllerStatus

대기할 상태입니다.

timeout
TimeSpan

서비스가 지정된 상태에 도달할 때까지 대기하는 시간을 지정하는 TimeSpan 개체입니다.

예외

desiredStatus 매개 변수가 ServiceControllerStatus 열거형에 정의된 값 중 하나가 아닌 경우

timeout 매개 변수에 대해 지정된 값이 만료된 경우

설명

사용 하 여 WaitForStatus 서비스 필요 상태에 도달한 때까지 처리의 애플리케이션을 일시 중단 합니다.

참고

메서드는 WaitForStatus 각 상태 검사 사이에 약 250밀리초를 대기합니다. WaitForStatus 는 관찰된 서비스가 로 변경된 후 해당 간격의 다른 상태로 즉시 변경 desiredStatus 되는 경우를 감지할 수 없습니다.

추가 정보

적용 대상