Ler em inglês

Partilhar via


ServiceControllerStatus Enumeração

Definição

Indica o estado atual do serviço.

C#
public enum ServiceControllerStatus
Herança
ServiceControllerStatus

Campos

ContinuePending 5

Continuar o serviço está pendente. Isso corresponde à constante SERVICE_CONTINUE_PENDING Win32, que é definida como 0x00000005.

Paused 7

O serviço está em pausa. Isso corresponde à constante SERVICE_PAUSED Win32, que é definida como 0x00000007.

PausePending 6

Pausar o serviço está pendente. Isso corresponde à constante SERVICE_PAUSE_PENDING Win32, que é definida como 0x00000006.

Running 4

O serviço está em execução. Isso corresponde à constante SERVICE_RUNNING Win32, que é definida como 0x00000004.

StartPending 2

O serviço está iniciando. Isso corresponde à constante SERVICE_START_PENDING Win32, que é definida como 0x00000002.

Stopped 1

Serviço não está sendo executado. Isso corresponde à constante SERVICE_STOPPED Win32, que é definida como 0x00000001.

StopPending 3

Serviço está parando. Isso corresponde à constante SERVICE_STOP_PENDING Win32, que é definida como 0x00000003.

Exemplos

O exemplo a seguir usa a ServiceController classe para verificar o status atual do serviço TelNet. Se o serviço for interrompido, o exemplo iniciará o serviço. Se o serviço estiver em execução, o exemplo interromperá o serviço.

C#

// Toggle the Telnet service -
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceController sc = new ServiceController("Telnet");
Console.WriteLine("The Telnet service status is currently set to {0}",
                  sc.Status.ToString());

if  ((sc.Status.Equals(ServiceControllerStatus.Stopped)) ||
     (sc.Status.Equals(ServiceControllerStatus.StopPending)))
{
   // Start the service if the current status is stopped.

   Console.WriteLine("Starting the Telnet service...");
   sc.Start();
}
else
{
   // Stop the service if its status is not set to "Stopped".

   Console.WriteLine("Stopping the Telnet service...");
   sc.Stop();
}

// Refresh and display the current service status.
sc.Refresh();
Console.WriteLine("The Telnet service status is now set to {0}.",
                   sc.Status.ToString());

Comentários

A ServiceControllerStatus enumeração é usada por uma instância da ServiceController classe para indicar se um serviço existente está em execução, parado, pausado ou se um comando Iniciar, Parar, Pausar ou Continuar está pendente.

Aplica-se a

Produto Versões
.NET Core 1.0, Core 1.1
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

Confira também