Condividi tramite


ServiceController.Stop Metodo

Definizione

Overload

Nome Descrizione
Stop()

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

Stop(Boolean)

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

Stop()

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

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

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.

Il servizio non è stato trovato.

Esempio

Nell'esempio seguente viene utilizzata 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 i servizi dipendono da questo servizio per il loro funzionamento, verranno arrestati prima che il servizio venga arrestato. La DependentServices proprietà contiene il set di servizi che dipendono da questo.

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

Vedi anche

Si applica a

Stop(Boolean)

Origine:
ServiceController.cs
Origine:
ServiceController.cs
Origine:
ServiceController.cs
Origine:
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 passarli truestopDependentServices o arrestarli manualmente prima di chiamare questo metodo.

Si applica a