Service not fully stopped after ServiceController.Stop()

后端 未结 5 941
时光说笑
时光说笑 2021-01-18 04:16
ServiceController serviceController = new ServiceController(someService);
serviceController.Stop();
serviceController.WaitForStopped();
DoSomething();
5条回答
  •  情书的邮戳
    2021-01-18 05:14

    ServiceController.WaitForStopped()/WaitForStatus() will return once the service implementation claims it has stopped. This doesn't necessary mean the process has released all of its resources and has exited. I've seen database other than SQL Server do this as well.

    If you really want to be sure the database is fully and truly stopped, you will have to interface with the database itself, get ahold of the process id and wait for it to exit, wait for locks on the files to be released, ...

提交回复
热议问题