A Windows service is an application with several additional methods that control the service manager, namely Stop() , Start() , Pause() , Continue() (or equivalents).
When "Start" is called the application domain, an initialized service class and the Start() method are created. When stopped, the Stop() method is called before the application domain is unloaded from memory.
You can see this with the task manager. An application does not exist in memory until a start is called and it disappears after Stop is completed.
Therefore, I believe that the answer to your life cycle lies in the life cycle of a standard .NET application, whether it be a command line, winforms or asp.net.
I would also advise that if you depend on the Dispose method, that is, there is probably a flaw lying somewhere in your design, in most cases the resources cleared by Dispose should be located more often than when the Host Service calls your component in Dispose . Most services are a mechanism for responding to a system event somewhere, in cases where this event comes from an unmanaged resource, you probably only want to grab the OnStart resource and release it OnStop in situations where the event does not come from unmanaged space, then you probably want to capture and free up unmanaged resources in a more JustInTime style, where you will receive them as a resource only when you need it and release them (via their Dispose method) as soon as you can. For further reading, see When and How to Use Dispose and .
source share