ServiceController.WaitForStatus Metódus

Definíció

Megvárja, amíg a szolgáltatás eléri a megadott állapotot.

Túlterhelések

Name Description
WaitForStatus(ServiceControllerStatus)

Végtelenül megvárja, amíg a szolgáltatás eléri a megadott állapotot.

WaitForStatus(ServiceControllerStatus, TimeSpan)

Megvárja, amíg a szolgáltatás eléri a megadott állapotot, vagy hogy a megadott időtúllépés lejárjon.

WaitForStatus(ServiceControllerStatus)

Forrás:
ServiceController.cs
Forrás:
ServiceController.cs
Forrás:
ServiceController.cs
Forrás:
ServiceController.cs

Végtelenül megvárja, amíg a szolgáltatás eléri a megadott állapotot.

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)

Paraméterek

desiredStatus
ServiceControllerStatus

A várakozási állapot.

Kivételek

A desiredStatus paraméter nem az enumerálásban ServiceControllerStatus definiált értékek egyike sem.

Példák

Az alábbi példa az ServiceController osztály használatával ellenőrzi, hogy a riasztási szolgáltatás leállt-e. Ha a szolgáltatás leáll, a példa elindítja a szolgáltatást, és megvárja, amíg a szolgáltatás állapota be nem áll 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

Megjegyzések

Az WaitForStatus alkalmazás feldolgozásának felfüggesztése, amíg a szolgáltatás el nem éri a szükséges állapotot.

Note

A WaitForStatus metódus körülbelül 250 ezredmásodpercet vár az egyes állapotellenőrzések között. WaitForStatus nem tudja észlelni, hogy a megfigyelt szolgáltatás az adott intervallumban egy desiredStatus másik állapotra vált, majd azonnal másik állapotba vált.

Lásd még

A következőre érvényes:

WaitForStatus(ServiceControllerStatus, TimeSpan)

Forrás:
ServiceController.cs
Forrás:
ServiceController.cs
Forrás:
ServiceController.cs
Forrás:
ServiceController.cs

Megvárja, amíg a szolgáltatás eléri a megadott állapotot, vagy hogy a megadott időtúllépés lejárjon.

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)

Paraméterek

desiredStatus
ServiceControllerStatus

A várakozási állapot.

timeout
TimeSpan

Egy TimeSpan objektum, amely megadja azt az időtartamot, amíg a szolgáltatás eléri a megadott állapotot.

Kivételek

A desiredStatus paraméter nem az enumerálásban ServiceControllerStatus definiált értékek egyike sem.

A paraméterhez timeout megadott érték lejár.

Megjegyzések

Az WaitForStatus alkalmazás feldolgozásának felfüggesztése, amíg a szolgáltatás el nem éri a szükséges állapotot.

Note

A WaitForStatus metódus körülbelül 250 ezredmásodpercet vár az egyes állapotellenőrzések között. WaitForStatus nem tudja észlelni, hogy a megfigyelt szolgáltatás az adott intervallumban egy desiredStatus másik állapotra vált, majd azonnal másik állapotba vált.

Lásd még

A következőre érvényes: