語言

ServiceBase.CanPauseAndContinue 屬性

定義

取得或設定一個值,表示服務是否可以暫停與恢復。

public:
 property bool CanPauseAndContinue { bool get(); void set(bool value); };
public bool CanPauseAndContinue { get; set; }
member this.CanPauseAndContinue : bool with get, set
Public Property CanPauseAndContinue As Boolean

屬性值

true如果服務可以暫停;否則,。 false

例外狀況

服務已經開始了。 服務開始後, CanPauseAndContinue 房產無法更改。

備註

在服務的建構子中設定屬性 CanPauseAndContinue 的值。

當服務暫停時,會停止正在進行的作業。 當你繼續服務(無論是透過服務控制管理器或程式化)時, OnContinue 就會執行。

向服務發送暫停請求可以節省系統資源。 暫停可能不會釋放所有系統資源,但停止會。 OnPause 且 OnContinue 通常實作為執行比 OnStop 和 OnStart更少的處理量。

當 CanPauseAndContinue 是 true時,會覆寫 OnPause ,並 OnContinue 指定當服務控制管理器(SCM)向你的服務傳遞暫停或繼續請求時應執行的處理方式。 OnContinue 應該實作以撤銷在 中的 OnPause處理。

若 CanPauseAndContinue 是 false,SCM 不會將暫停或繼續請求傳給服務,因此 OnPause 即使 and OnContinue 方法已實作,也不會被呼叫。 在 SCM 中,Pause當 是 Continue時,和 CanPauseAndContinue 控制項會被禁用。false

適用於

另請參閱