Quick (really) question about windows services.
According to the documentation, services require a minimum of 2 methods OnStart() and OnStop() to be useful.
OnStart() cannot contain the main execution code, it shouldn't loop, block or otherwise prevent the OnStart() method from returning quickly.
The Question:
If the above is true...it seems like, for a service to have any use at all, the OnStart() method MUST execute a different method on a different thread because running a method on the same thread from within the OnStart() method would cause blocking if that other method looped infinately...OnStart() would never return.
Is that correct?
Also, one other question for bonus points.
If a service implements OnCustomCommand(), you pass the custom command to the Service Controller and the Service Controller tells the service "Hey! do this command" and then ignores the service (doesn't wait for the service to do anything, it's just the messenger).
The question is, when the Service Controller does that, does the simple inclusion of the OnCustomCommand() method automatically listen for those commands? I guess what I mean is, if OnStart() starts a new thread (called ThreadA) and ThreadA runs in an infinite loop or blocks, while ThreadA is sitting there serving up whatever service it's supposed to and looping like there is no tomorrow, the OnStart() method that sprung ThreadA has ended which was on a different thread. Is that original (main) thread gone? Who is the Service Controller talking to? ThreadA? or does the controller instantiate an instance of OnCustomCommand() on a new thread called, say, ThreadB and just jump to the OnCustomCommand() method and skip the OnStart() method?
What happens if two commands are issued to the service controller in succession? Does the service controller wait for the first custom command to return before issuing the second one or does the service controller start yet another thread to process the new custom command?
I'm just a little confused about how the services communicate with the Service Controller and how custom commands are handled. If the service controller is going to start sprouting off a million new threads every time a custom command is issued...aren't you eventually going to run into potential deadlock situations, memory issues and/or CPU bottlenecking?
Could someone clarify this for me?
Yeah...so I lied...it wasn't a quick question. Sorry :)