ServiceController.CanStop Property

Definition

Gets a value indicating whether the service can be stopped after it has started.

public bool CanStop { get; }
[System.ServiceProcess.ServiceProcessDescription("SPCanStop")]
public bool CanStop { get; }

Property Value

true if the service can be stopped and the OnStop() method called; otherwise, false.

Attributes

Exceptions

An error occurred when accessing a system API.

The service was not found.

Examples

The following example demonstrates the use of the CanStop property to determine whether a service provides a handler for a stop event. This example is part of a larger example that is provided for the ServiceController class.

// Display properties for the Simple Service sample
// from the ServiceBase example.
ServiceController sc = new ServiceController("Simple Service");
Console.WriteLine("Status = " + sc.Status);
Console.WriteLine("Can Pause and Continue = " + sc.CanPauseAndContinue);
Console.WriteLine("Can ShutDown = " + sc.CanShutdown);
Console.WriteLine("Can Stop = " + sc.CanStop);

Applies to

מוצר גירסאות
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided)
.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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)