简体   繁体   中英

Overriding Stop in a Windows Service

I have this windows service class here written in C#. It has a member function called Stop but apparently its base class ServiceBase also has a Stop function.

ServiceBase.Stop() calls OnStop which is overriden in the service again which calls this.Stop() in its own object again.

Now VS gives the warning: Server.Stop() hides inherited member System.ServiceProcess.ServiceBase.Stop() . Use the new keyword if hiding was intended

Can I just use new without changing the behaviour of the service?

If you aren't intending to override the base Stop() method, why don't you just rename it to avoid any ambiguity?

If you want to do something before or after the service controller causes Stop() to be called, override it - and then call base.Stop() either before or after your own code as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM