共用方式為


ServiceController.CanShutdown 屬性

定義

取得值,表示當系統關閉時是否應該通知服務。

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

屬性值

Boolean

如果當系統關閉時應該通知服務,則為 true,否則為 false

屬性

例外狀況

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

找不到服務。

範例

下列範例示範如何使用 CanShutdown 屬性來判斷服務是否提供關機事件的處理常式。 這個範例是針對 類別提供的較大範例的 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())

適用於