ServiceController.Start Metodo

Definizione

avvia il servizio.

Overload

Start()

Avvia il servizio, senza passare argomenti.

Start(String[])

Avvia il servizio, passando gli argomenti specificati.

Start()

Origine:
ServiceController.cs
Origine:
ServiceController.cs
Origine:
ServiceController.cs
Origine:
ServiceController.cs

Avvia il servizio, senza passare argomenti.

public:
 void Start();
public void Start ();
member this.Start : unit -> unit
Public Sub Start ()

Eccezioni

Si è verificato un errore durante l'accesso a un'API di sistema.

Servizio non trovato.

Esempio

Nell'esempio seguente viene usata 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 è 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

Non è possibile chiamare Stop il servizio finché lo stato del controller di servizio non è Running.

Vedi anche

Si applica a

Start(String[])

Origine:
ServiceController.cs
Origine:
ServiceController.cs
Origine:
ServiceController.cs
Origine:
ServiceController.cs

Avvia il servizio, passando gli argomenti specificati.

public:
 void Start(cli::array <System::String ^> ^ args);
public void Start (string[] args);
member this.Start : string[] -> unit
Public Sub Start (args As String())

Parametri

args
String[]

Matrice di argomenti da passare al servizio quando viene avviato.

Eccezioni

Si è verificato un errore durante l'accesso a un'API di sistema.

Impossibile avviare il servizio.

args è null.

-oppure-

Un membro della matrice è null.

Commenti

Non è possibile chiamare Stop il servizio finché lo stato del controller di servizio non è Running.

Vedi anche

Si applica a