ServiceController.Start Metoda

Definicja

Uruchamia usługę.

Przeciążenia

Start()

Uruchamia usługę, przekazując bez argumentów.

Start(String[])

Uruchamia usługę, przekazując określone argumenty.

Start()

Uruchamia usługę, przekazując bez argumentów.

C#
public void Start ();

Wyjątki

Wystąpił błąd podczas uzyskiwania dostępu do interfejsu API systemu.

Nie można odnaleźć usługi.

Przykłady

W poniższym przykładzie użyto klasy w ServiceController celu sprawdzenia, czy usługa alertów została zatrzymana. Jeśli usługa zostanie zatrzymana, przykład uruchamia usługę i czeka na ustawienie stanu usługi na Runningwartość .

C#

// 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.ToString());

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.ToString());
   }
   catch (InvalidOperationException)
   {
      Console.WriteLine("Could not start the Alerter service.");
   }
}

Uwagi

Nie można wywołać Stop usługi do momentu, gdy stan kontrolera usługi to Running.

Zobacz też

Dotyczy

.NET Core 1.1 i inne wersje
Produkt Wersje
.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

Start(String[])

Uruchamia usługę, przekazując określone argumenty.

C#
public void Start (string[] args);

Parametry

args
String[]

Tablica argumentów, które mają być przekazywane do usługi po jej uruchomieniu.

Wyjątki

Wystąpił błąd podczas uzyskiwania dostępu do interfejsu API systemu.

Nie można uruchomić usługi.

args to null.

-lub- Element członkowski tablicy to null.

Uwagi

Nie można wywołać Stop usługi do momentu, gdy stan kontrolera usługi to Running.

Zobacz też

Dotyczy

.NET Core 1.1 i inne wersje
Produkt Wersje
.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