i write a windows service by c# 4 and override some methods for it, like OnStart() and OnStop() and OnPause() and OnContinue() and OnShutdown().
i can start or stop this windows service, but i can not pause or continue it whether by programming or in services.msc. in other words, Start and Stop are Enable and Pause and Resume Options is Disable.
what is problem?
Thread object you create in the OnStart() callback. The _shutdownEvent field holds a system-level event construct that will be used to signal the thread to stop running on service shutdown. In the OnStart() callback, create and start your thread. You need a function named WorkerThreadFunc in order for this to work.
When a service is paused, it can maintain internal state, including cached information or possibly even a queue of waiting work items. The service can then be resumed to pick up where it left off. If the service is stopped, internal state is discarded. Starting the service again should repeat all initialization.
You need to set the CanPauseAndContinue
property to true as well. This is documented in 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With