1

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?

4

1 回答 1

1

如果您不打算覆盖基本Stop()方法,为什么不直接重命名它以避免任何歧义?

如果您想在Stop()调用服务控制器之前或之后执行某些操作,请覆盖它 - 然后base.Stop()根据需要在您自己的代码之前或之后调用。

于 2012-11-30T13:10:45.547 回答