What guarantees does the service control manager (SCM) make about the method calls on a service?
Does it guarantee against cases like the following?
- OnStart/OnPause/OnContinue while the service is stopped
- OnStart/OnPause while the service is paused
- OnStop/OnContinue while the service is running
- Any command method being called while a command method is already being executed
- OnStart while OnStart is already executing
- OnStop while OnPause is executing
The best references I've found so far seem to indicate that these guarantees are indeed made, but the only reference in the documentation I found was pretty vague, so I'm trying to find a better reference.
Here's a thread on the MSDN forums that says that the SCM ensures the state is consistent or "At least I've never found a case where [the SCM sending a stop request if the service isn't running or paused] could happen".
Here's the best reference I've found so far in the docs:
These methods [OnStart/OnStop/etc.] represent states that the service moves through in its lifetime; the service transitions from one state to the next. For example, you will never get the service to respond to an OnContinue command before OnStart has been called.
Michael Taylor provided a good answer to this question on the MSDN forums referencing the Win32 API which documents what the SCM will do in response to invalid control codes (reject them in various ways).