ServiceController.WaitForStatus Metoda

Definice

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

Přetížení

Name Description
WaitForStatus(ServiceControllerStatus)

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

WaitForStatus(ServiceControllerStatus, TimeSpan)

Čeká na dosažení zadaného stavu nebo vypršení zadaného časového limitu služby.

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í žádnou 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 zastavena, příklad spustí službu a počká, až bude stav služby nastaven 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

Slouží WaitForStatus k pozastavení zpracování aplikace, dokud služba nedosáhne požadovaného stavu.

Note

Metoda WaitForStatus čeká přibližně 250 milisekund mezi jednotlivými kontrolami stavu. WaitForStatus aplikace nemůže zjistit případ zjištěné služby, která se v daném intervalu změní na desiredStatus a potom okamžitě na jiný stav.

Viz také

Platí pro

WaitForStatus(ServiceControllerStatus, TimeSpan)

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

Čeká na dosažení zadaného stavu nebo vypršení zadaného časového limitu služby.

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í na dosažení zadaného stavu služby.

Výjimky

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

Hodnota zadaná pro timeout parametr vyprší.

Poznámky

Slouží WaitForStatus k pozastavení zpracování aplikace, dokud služba nedosáhne požadovaného stavu.

Note

Metoda WaitForStatus čeká přibližně 250 milisekund mezi jednotlivými kontrolami stavu. WaitForStatus aplikace nemůže zjistit případ zjištěné služby, která se v daném intervalu změní na desiredStatus a potom okamžitě na jiný stav.

Viz také

Platí pro