Share via


ServiceController.WaitForStatus Metoda

Definice

Čeká, až služba dosáhne zadaného stavu.

Přetížení

WaitForStatus(ServiceControllerStatus)

Nekonečně čeká, až služba dosáhne zadaného stavu.

WaitForStatus(ServiceControllerStatus, TimeSpan)

Počká, až služba dosáhne zadaného stavu, nebo na vypršení zadaného časového limitu.

WaitForStatus(ServiceControllerStatus)

Zdroj:
ServiceController.cs
Zdroj:
ServiceController.cs
Zdroj:
ServiceController.cs
Zdroj:
ServiceController.cs

Nekonečně čeká, až služba dosáhne zadaného stavu.

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)

Parametry

desiredStatus
ServiceControllerStatus

Stav, na který se má čekat.

Výjimky

Parametr desiredStatus není žádná z hodnot definovaných ve výčtu ServiceControllerStatus .

Příklady

Následující příklad používá ServiceController třídu ke kontrole, zda je služba Alerter zastavena. Pokud je služba zastavená, příklad ji spustí a počká, dokud se stav služby nenastaví na 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

Poznámky

Umožňuje WaitForStatus pozastavit zpracování aplikace, dokud služba nedosáhne požadovaného stavu.

Poznámka

Metoda WaitForStatus čeká přibližně 250 milisekund mezi každou kontrolou stavu. WaitForStatus nemůže zjistit případ, kdy se pozorovaná služba v tomto intervalu desiredStatus změní na a pak okamžitě na jiný stav.

Viz také

Platí pro

WaitForStatus(ServiceControllerStatus, TimeSpan)

Zdroj:
ServiceController.cs
Zdroj:
ServiceController.cs
Zdroj:
ServiceController.cs
Zdroj:
ServiceController.cs

Počká, až služba dosáhne zadaného stavu, nebo na vypršení zadaného časového limitu.

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)

Parametry

desiredStatus
ServiceControllerStatus

Stav, na který se má čekat.

timeout
TimeSpan

Objekt TimeSpan určující dobu čekání, než služba dosáhne zadaného stavu.

Výjimky

Parametr desiredStatus není žádná z hodnot definovaných ve výčtu ServiceControllerStatus .

Hodnota zadaná pro timeout parametr vyprší.

Poznámky

Umožňuje WaitForStatus pozastavit zpracování aplikace, dokud služba nedosáhne požadovaného stavu.

Poznámka

Metoda WaitForStatus čeká přibližně 250 milisekund mezi každou kontrolou stavu. WaitForStatus nemůže zjistit případ, kdy se pozorovaná služba v tomto intervalu desiredStatus změní na a pak okamžitě na jiný stav.

Viz také

Platí pro