gpt4 book ai didi

c# - 如何通过 C# 暂停和继续 Windows 服务

转载 作者:行者123 更新时间:2023-12-03 17:59:17 25 4
gpt4 key购买 nike

我用 c# 4 编写了一个 Windows 服务并覆盖了它的一些方法,比如 OnStart() 和 OnStop() 和 OnPause() 和 OnContinue() 和 OnShutdown()。

我可以启动或停止此 Windows 服务,但无论是通过编程还是在 services.msc 中,我都无法暂停或继续它。换句话说,Start 和Stop 是Enable,Pause 和Resume Options 是Disable。

enter image description here

什么是问题?

最佳答案

您需要设置 CanPauseAndContinue 属性也为真。这记录在 OnContinue 中:

OnContinue is expected to be overridden when the CanPauseAndContinue property is true.

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. In the SCM, the Pause and Continue controls are disabled when CanPauseAndContinue is false.

关于c# - 如何通过 C# 暂停和继续 Windows 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16249428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com