ServiceBase.CanPauseAndContinue 屬性


取得或設定值,指出服務是否可以暫停和繼續。Gets or sets a value indicating whether the service can be paused and resumed.

 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,否則為 falsetrue if the service can be paused; otherwise, false.


已經啟動服務。The service has already been started. 一旦已經啟動服務,就無法變更 CanPauseAndContinue 屬性。The CanPauseAndContinue property cannot be changed once the service has started.


在服務的函式CanPauseAndContinue中,設定屬性的值。Set the value of the CanPauseAndContinue property in the constructor for the service.

當服務暫停時,它會停止正在執行的作業。When a service is paused, it halts what it is doing. 當您繼續服務(透過服務控制管理員或以程式設計方式)時OnContinue ,會執行。When you continue the service (either through the Service Control Manager or programmatically), OnContinue runs.

將暫停要求傳送至服務可節省系統資源。Sending a Pause request to the service can conserve system resources. [暫停] 可能不會釋放所有系統資源,但會停止執行。Pause may not release all system resources, but Stop does. OnPauseOnContinue通常會實作為執行比OnStopOnStart更少的處理。OnPause and OnContinue are often implemented to perform less processing than OnStop and OnStart.

CanPauseAndContinuetrue時, OnPauseOnContinue寫和以指定當服務控制管理員(SCM)將暫停或繼續要求傳遞至您的服務時,應該發生的處理。When CanPauseAndContinue is true, override OnPause and OnContinue to specify the processing that should occur when the Service Control Manager (SCM) passes a Pause or Continue request to your service. OnContinue應該實作為復原中OnPause的處理。OnContinue should be implemented to undo the processing in OnPause.

如果CanPauseAndContinue OnPause OnContinuefalse,則 SCM 不會將暫停或繼續要求傳遞至服務,因此即使已實作為和方法,也不會呼叫和方法。If CanPauseAndContinue is false, the SCM will not pass Pause or Continue requests to the service, so the OnPause and OnContinue methods will not be called even if they are implemented. Pause SCM 中,當為Continue CanPauseAndContinue false時,會停用和控制項。In the SCM, the Pause and Continue controls are disabled when CanPauseAndContinue is false.