I'm creating a C#.Net Windows Service and am wondering if you always have to call base.OnStop();
in the service's OnStop()
method and why?
protected override void OnStop()
{
threadRunning = false;
this.ExitCode = 0;
base.OnStop();
}
From the documentation on ServiceBase.OnStop:
OnStop is expected to be overridden in the derived class. For the service to be useful, OnStart and OnStop should both be implemented in your service class.
So it's really used as a notification to your service that it is stopping.
A glance at the .NET source code for ServiceBase.cs reveals the method does nothing:
protected virtual void OnStop()
{
}
So, do you need to call it? No. But it is still good form to do so. The base implementation may change someday.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With