服务ServiceController.Stop后没有完全停止() [英] Service not fully stopped after ServiceController.Stop()

查看:279
本文介绍了服务ServiceController.Stop后没有完全停止()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ServiceController serviceController = new ServiceController(someService);
serviceController.Stop();
serviceController.WaitForStopped();
DoSomething();

SomeService适用于一个SQLServer文件。 DoSomething的()想要复制SQL文件。如果SomeService未完全关闭它会抛出一个错误,因为数据库文件仍然锁定。在上述code,我得到过去的WaitForStopped()方法,但该服务不释放数据库文件,直到之后DoSomething的(),所以我得到一个错误。

SomeService works on a sqlserver file. DoSomething() wants to copy that SQL file. If SomeService isn't closed fully it will throw an error because the database file is still locked. In the aforementioned code, I get past the WaitForStopped() method and yet the service doesn't release the database file until after DoSomething(), thus I get an error.

做一些调查,我发现DoSomething的方法调用之前我看到服务控制器状态显示已停止,但寻找一些procmon中记录的服务版本的数据库文件,我从DoSomething的抛出的错误后。

Doing some more investigation, I find that before the DoSomething method call I see that the service controller status shows a stopped and yet looking at some ProcMon logs the service releases the database file after I'm thrown an error from DoSomething.

另外,如果我把WaitForStopped和DoSomething的方法,比如... 5秒之间的Thread.sleep代码,数据库文件被释放,一切都很好。没有担保的解决方案,我正在寻找但是。

Also, if I put a Thread.Sleep between the WaitForStopped and the DoSomething method for say... 5 seconds, the database file is released and all is well. Not the solution of surety I'm looking for however.

任何想法?

推荐答案

ServiceController.WaitForStopped()/ WaitForStatus()将返回各服一次实现声称它已停止。这并不意味着必需进程已经释放了所有的资源和已经退出。我见过的数据库是SQL Server以外做到这一点。

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.

如果你真的想成为确保数据库是完全,真正停止,你会与数据库本身的接口,得到阿霍德进程ID,并等待它退出,等待中的文件锁被释放......

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, ...

这篇关于服务ServiceController.Stop后没有完全停止()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆