ServiceController.WaitForStatus Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Espera que o serviço atinja o estado especificado.
Sobrecargas
| Name | Description |
|---|---|
| WaitForStatus(ServiceControllerStatus) |
Espera infinitamente que o serviço atinja o estado especificado. |
| WaitForStatus(ServiceControllerStatus, TimeSpan) |
Espera que o serviço atinja o estado especificado ou que o tempo de espera expire. |
WaitForStatus(ServiceControllerStatus)
Espera infinitamente que o serviço atinja o estado especificado.
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)
Parâmetros
- desiredStatus
- ServiceControllerStatus
O estado a esperar.
Exceções
O desiredStatus parâmetro não corresponde a nenhum dos valores definidos na ServiceControllerStatus enumeração.
Exemplos
O exemplo seguinte utiliza a ServiceController classe para verificar se o serviço Alerter está parado. Se o serviço for interrompido, o exemplo inicia o serviço e espera até que o estado do serviço seja definido para 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
Observações
Usar WaitForStatus para suspender o processamento de uma candidatura até que o serviço atinja o estado exigido.
Note
O WaitForStatus método espera aproximadamente 250 milissegundos entre cada verificação de estado.
WaitForStatus não é possível detetar o caso do serviço observado mudar para o desiredStatus e depois imediatamente para outro estado nesse intervalo.
Ver também
Aplica-se a
WaitForStatus(ServiceControllerStatus, TimeSpan)
Espera que o serviço atinja o estado especificado ou que o tempo de espera expire.
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)
Parâmetros
- desiredStatus
- ServiceControllerStatus
O estado a esperar.
- timeout
- TimeSpan
Um TimeSpan objeto que especifica o tempo de espera para o serviço atingir o estado especificado.
Exceções
O desiredStatus parâmetro não corresponde a nenhum dos valores definidos na ServiceControllerStatus enumeração.
O valor especificado para o timeout parâmetro expira.
Observações
Usar WaitForStatus para suspender o processamento de uma candidatura até que o serviço atinja o estado exigido.
Note
O WaitForStatus método espera aproximadamente 250 milissegundos entre cada verificação de estado.
WaitForStatus não é possível detetar o caso do serviço observado mudar para o desiredStatus e depois imediatamente para outro estado nesse intervalo.