我用 c# 4 编写了一个 Windows 服务并覆盖了它的一些方法,比如 OnStart() 和 OnStop() 和 OnPause() 和 OnContinue() 和 OnShutdown()。
我可以启动或停止此 Windows 服务,但无论是通过编程还是在 services.msc 中,我都无法暂停或继续它。换句话说,Start 和Stop 是Enable,Pause 和Resume Options 是Disable。
什么是问题?
最佳答案
您需要设置 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/