When deriving from ServiceBase
, should I call the methods of the base class, too?
protected override void OnStart(string[] args)
{
//
// The stuff I do when the service starts.
//
base.OnStart(args); // Do I need to call this?
}
The short answer is yes, you should.
In this specific case, the base implementation of the OnStart method doesn't do anything significant, but that is an implementation detail which could change at any time. As a general practice, you should always call the base method unless you have a good reason not to.
If you decompile the service base with ILSpy or similar, you will see, that OnStart, OnStop, etc. do nothing (at least in .NET 4.0/4.5).
But this behaviour could change some time, so there could be unwanted or unpredicted behaviour in future releases of .NET, if you do not call it.
I think it's a good practice to call those base.OnEvent()-Methods.
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