The windows service is effectively an application with a few extra methods exposed for the service manager to control it, namely Stop()
, Start()
, Pause()
, Continue()
(or equivalents).
When Start is called the application domain is created, the service class initialised and the Start()
method called. On stop the Stop()
method is called before the application domain is unloaded from memory.
You can see this with task manager. The application doesn't exist in memory until the start is called and it disappears after the Stop is completed.
Therefore I believe that the answer to your lifecycle question lies in the lifecycle of a standard .NET application, be it command line, winforms or asp.net.
I would also advise though that if you are dependent on the Dispose method then there is a probably a flaw lieing somewhere in your design, under most circumstances the resources cleaned up by a Dispose should be disposed more frequently than when the Service Host calls your component to Dispose. Most services are mearly a mechanism for responding to a system event somewhere, in the cases where this event comes from an unmanaged resource, you probably only want to grab the resource OnStart and release it OnStop, in situations where the event is not originating in unmanaged space then you probably want to grab and release the unmanaged resources in a more JustInTime type manner where by you grab them as a resource only when you need them and release them (via their Dispose method) as soon as you can. For further reading check out When and how to use dispose and .Net dispose pattern