ServiceController.Start Metode

Definisi

Memulai layanan.

Overload

Nama Deskripsi
Start()

Memulai layanan, tidak meneruskan argumen.

Start(String[])

Memulai layanan, meneruskan argumen yang ditentukan.

Start()

Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs

Memulai layanan, tidak meneruskan argumen.

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

Pengecualian

Terjadi kesalahan saat mengakses API sistem.

Layanan tidak ditemukan.

Contoh

Contoh berikut menggunakan ServiceController kelas untuk memeriksa apakah layanan Pemberitahuan dihentikan. Jika layanan dihentikan, contoh memulai layanan dan menunggu hingga status layanan diatur ke 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

Keterangan

Anda tidak dapat memanggil Stop layanan hingga status pengontrol layanan adalah Running.

Lihat juga

Berlaku untuk

Start(String[])

Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs
Sumber:
ServiceController.cs

Memulai layanan, meneruskan argumen yang ditentukan.

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

Parameter

args
String[]

Array argumen untuk diteruskan ke layanan saat dimulai.

Pengecualian

Terjadi kesalahan saat mengakses API sistem.

Layanan tidak dapat dimulai.

args adalah null.

-atau-

Anggota array adalah null.

Keterangan

Anda tidak dapat memanggil Stop layanan hingga status pengontrol layanan adalah Running.

Lihat juga

Berlaku untuk