I try for the first time to create a service. The service is started automatically as user.
I want to handle the shutdown to also do some cleanups.
For that I tried the following: In the service I set
CanShutdown to true. In the Service file I used the follwoing code:
protected override void OnShutdown()
{
this.eventLog.WriteEntry("OnShutdown.");
this.OnStop(); // does some cleanup
base.OnShutdown();
}
(where Eventlog is System.Diagnostic.EventLog which logs to Application (and is also used in OnStart and OnStop wchich write the message to eventlog).
So for me it looks like the OnShutdown is not triggered.
What can be the possible reason? (I see no possibility to debug during shutdown)