共用方式為


ServiceController.CanStop 屬性

定義

取得值,表示服務啟動後是否可以停止。

public:
 property bool CanStop { bool get(); };
public bool CanStop { get; }
[System.ServiceProcess.ServiceProcessDescription("SPCanStop")]
public bool CanStop { get; }
member this.CanStop : bool
[<System.ServiceProcess.ServiceProcessDescription("SPCanStop")>]
member this.CanStop : bool
Public ReadOnly Property CanStop As Boolean

屬性值

Boolean

如果可以停止服務並且呼叫 OnStop() 方法,則為 true,否則為 false

屬性

例外狀況

存取系統 API 時發生的錯誤。

找不到服務。

範例

下列範例示範如何使用 CanStop 屬性來判斷服務是否提供停止事件的處理常式。 這個範例是針對 類別提供的較大範例的 ServiceController 一部分。

// 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);
' Display properties for the Simple Service sample 
' from the ServiceBase example
Dim sc As New ServiceController("Simple Service")
Console.WriteLine("Status = " + sc.Status.ToString())
Console.WriteLine("Can Pause and Continue = " + _
    sc.CanPauseAndContinue.ToString())
Console.WriteLine("Can ShutDown = " + sc.CanShutdown.ToString())
Console.WriteLine("Can Stop = " + sc.CanStop.ToString())

適用於