ServiceController.WaitForStatus Metodo

Definizione

Attende che il servizio raggiunga lo stato specificato.

Overload

WaitForStatus(ServiceControllerStatus)

Attende che il servizio raggiunga lo stato specificato senza limiti di tempo.

WaitForStatus(ServiceControllerStatus, TimeSpan)

Attende che il servizio raggiunga lo stato specificato oppure la scadenza del timeout specificato.

WaitForStatus(ServiceControllerStatus)

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

Attende che il servizio raggiunga lo stato specificato senza limiti di tempo.

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)

Parametri

desiredStatus
ServiceControllerStatus

Stato da attendere.

Eccezioni

Il parametro desiredStatus non corrisponde a nessuno dei valori definiti nell'enumerazione ServiceControllerStatus.

Esempio

Nell'esempio seguente viene utilizzata la ServiceController classe per verificare se il servizio Alerter viene arrestato. Se il servizio viene arrestato, l'esempio avvia il servizio e attende fino a quando lo stato del servizio non viene impostato su 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

Commenti

Usare WaitForStatus per sospendere l'elaborazione di un'applicazione fino a quando il servizio non ha raggiunto lo stato richiesto.

Nota

Il WaitForStatus metodo attende circa 250 millisecondi tra ogni controllo di stato. WaitForStatus non è in grado di rilevare il caso del servizio osservato che passa a desiredStatus e quindi immediatamente a un altro stato in tale intervallo.

Vedi anche

Si applica a

WaitForStatus(ServiceControllerStatus, TimeSpan)

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

Attende che il servizio raggiunga lo stato specificato oppure la scadenza del timeout specificato.

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)

Parametri

desiredStatus
ServiceControllerStatus

Stato da attendere.

timeout
TimeSpan

Oggetto TimeSpan che specifica il tempo di attesa prima che il servizio raggiunga lo stato specificato.

Eccezioni

Il parametro desiredStatus non corrisponde a nessuno dei valori definiti nell'enumerazione ServiceControllerStatus.

Il valore specificato per il parametro timeout ha una scadenza.

Commenti

Usare WaitForStatus per sospendere l'elaborazione di un'applicazione fino a quando il servizio non ha raggiunto lo stato richiesto.

Nota

Il WaitForStatus metodo attende circa 250 millisecondi tra ogni controllo di stato. WaitForStatus non è in grado di rilevare il caso del servizio osservato che passa a desiredStatus e quindi immediatamente a un altro stato in tale intervallo.

Vedi anche

Si applica a