ServiceController.Stop Metodo

Definizione

Overload

Stop()

Arresta questo servizio e tutti i servizi da esso dipendenti.

Stop(Boolean)

Arresta il servizio e facoltativamente tutti i servizi dipendenti da questo servizio.

Stop()

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

Arresta questo servizio e tutti i servizi da esso dipendenti.

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

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 controllare lo stato corrente del servizio Telnet. Se il servizio viene arrestato, l'esempio avvia il servizio. Se il servizio è in esecuzione, l'esempio arresta il servizio.

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

Commenti

Se tutti i servizi dipendono da questo servizio per l'operazione, verranno arrestati prima che questo servizio venga arrestato. La DependentServices proprietà contiene il set di servizi che dipendono da questo.

Se si arresta un servizio a seconda del servizio, chiamare il Stop metodo su questo servizio all'interno Stop del metodo del servizio padre. La ServicesDependedOn proprietà contiene i servizi a seconda del servizio.

Vedi anche

Si applica a

Stop(Boolean)

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

Arresta il servizio e facoltativamente tutti i servizi dipendenti da questo servizio.

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

Parametri

stopDependentServices
Boolean

true per arrestare tutti i servizi dipendenti in esecuzione insieme al servizio; false per arrestare solo il servizio.

Commenti

Se altri servizi dipendono da questo, è necessario passare truestopDependentServices o arrestarli manualmente prima di chiamare questo metodo.

Si applica a