Bagikan melalui


ServiceController.Stop Metode

Definisi

Overload

Nama Deskripsi
Stop()

Menghentikan layanan ini dan layanan apa pun yang bergantung pada layanan ini.

Stop(Boolean)

Menghentikan layanan dan secara opsional layanan apa pun yang bergantung pada layanan ini.

Stop()

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

Menghentikan layanan ini dan layanan apa pun yang bergantung pada layanan ini.

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

Pengecualian

Terjadi kesalahan saat mengakses API sistem.

Layanan tidak ditemukan.

Contoh

Contoh berikut menggunakan ServiceController kelas untuk memeriksa status layanan Telnet saat ini. Jika layanan dihentikan, contoh memulai layanan. Jika layanan berjalan, contohnya akan menghentikan layanan.

// Toggle the Telnet service - 
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceController^ sc = gcnew ServiceController(  "Telnet" );
if ( sc )
{
   Console::WriteLine(  "The Telnet service status is currently set to {0}", sc->Status );
   if ( (sc->Status == (ServiceControllerStatus::Stopped) ) || (sc->Status == (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 );

// 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);

if ((sc.Status == ServiceControllerStatus.Stopped) ||
    (sc.Status == 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);

' Toggle the Telnet service - 
' If it is started (running, paused, etc), stop the service.
' If it is stopped, start the service.
Dim sc As New ServiceController("Telnet")
Console.WriteLine("The Telnet service status is currently set to {0}", sc.Status)

If sc.Status.Equals(ServiceControllerStatus.Stopped) Or sc.Status.Equals(ServiceControllerStatus.StopPending) Then
   ' 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()
End If

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

Keterangan

Jika ada layanan yang bergantung pada layanan ini untuk operasi mereka, layanan akan dihentikan sebelum layanan ini dihentikan. Properti DependentServices berisi sekumpulan layanan yang bergantung pada yang satu ini.

Jika Anda menghentikan layanan yang bergantung pada layanan ini, panggil Stop metode pada layanan ini dalam Stop metode layanan induk. Properti ServicesDependedOn berisi layanan yang bergantung pada layanan ini.

Lihat juga

Berlaku untuk

Stop(Boolean)

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

Menghentikan layanan dan secara opsional layanan apa pun yang bergantung pada layanan ini.

public:
 void Stop(bool stopDependentServices);
public void Stop(bool stopDependentServices);
member this.Stop : bool -> unit
Public Sub Stop (stopDependentServices As Boolean)

Parameter

stopDependentServices
Boolean

true untuk menghentikan semua layanan dependen yang berjalan bersama dengan layanan; false untuk menghentikan hanya layanan.

Keterangan

Jika ada layanan lain yang bergantung pada layanan ini, Anda perlu meneruskannya truestopDependentServices atau menghentikannya secara manual sebelum memanggil metode ini.

Berlaku untuk