ServiceController.Stop() 似乎没有停止任何事情
我的开发盒是 Windows 7 (x64) 机器。我有一些代码(C#,.net 2.0),在某些情况下,检查服务是否正在运行然后停止它。
ServiceController matchedService = //My Service!
//If statements and such
matchedService.Stop();
matchedService.WaitForStatus(ServiceControllerStatus.Stopped);
现在,我可以验证 MyService 实际上已安装并正在运行。我可以告诉你,我在调试时以管理员身份运行 Visual Studio 2008。我还可以验证在几个 If 语句之后,我最终到达了编程的 .Stop() 和 .WaitForStatus() 部分。我确实知道,如果跳过 .Stop() 调用,服务本身就会继续运行(在服务中查看它,尽管我想到也许我应该为此获取更好的工具。我我确信有一些 sysinternals 工具可以为我提供更多信息)。当我跳过 .WaitForStatus() 调用时,我基本上会等待停止状态。 。 。永远。好吧,昨天我让它在那里放置了超过 15 分钟(两次),但没有任何反应。我们永远不会到达下一行代码。感觉就像鲍伊的《Space Oddity》(你知道我正在谈论的部分)。
关于 MyService 有很多你一无所知的事情。你不会明白的事情。你做不到的事情。 。 。让我明确地说明这一点。没有服务依赖于 MyService,并且 MyService 也不依赖于其他服务。 附录 MyOtherService 和 SonOfMyService 在代码中的这一点上似乎都表现正确。所有这些服务都具有相同的特征(它们是我们在秘密实验室中孵化的自己的服务,没有依赖性)。 MyService 安装有问题吗?
我确实知道,如果我此时停止调试,MyService 仍会在服务中列为正在运行(即使在点击刷新后)。如果我尝试重新启动它(或再次运行我的应用程序并到达这一点),我会收到一条有关它无法接受控制消息的消息。之后,该服务显示为已停止,我可以正常启动它。
为什么服务没有停止?这是win 7的怪癖吗?我对 ServiceController 或 Win Services 的总体理解失败?
My dev box is a Windows 7 (x64) machine. I've got some code (C#, .net 2.0) that in certain circumstances, checks to see if a service is running and then stops it.
ServiceController matchedService = //My Service!
//If statements and such
matchedService.Stop();
matchedService.WaitForStatus(ServiceControllerStatus.Stopped);
Now, I can verify MyService is in fact installed and running. I can tell you I am running Visual Studio 2008 as an administrator while debugging. I can also verify that after a couple of If statements, I wind up at the .Stop() and .WaitForStatus() portion of the programming. I do know that if step over the .Stop() call, the service itself just keeps running (looking at it in Services, though it occurs to me perhaps I should grab a better tool for this. I'm sure there's some sysinternals tool that might give me more information). As I step over the .WaitForStatus() call, I basically wind up waiting for the stopped status. . . forever. Well, I let it sit there for over 15 minutes yesterday (twice) and nothing happens. We never make it to the next line of code. It feels exactly like Bowie's Space Oddity (you know the part I am talking about).
There's a lotta things about MyService you don't know anything about. Things you wouldn't understand. Things you couldn't. . . let me state this plainly. No services depend on MyService and MyService depends on no other services. Addendum MyOtherService and SonOfMyService both seem to behave correctly at this point in the code. All of these services share the same characteristics (they're our own services we hatched in a secret lab and have no dependencies). Is it possible there is something wrong with the MyService install or something?
I do know that if I stop debugging at this point, MyService is still listed as running in Services (even after hitting refresh). If I try to restart it then (or run my application again and get to this point), I get a message about it not being able to accept control messages. After that, the service shows up as stopped and I can start it normally.
Why isn't the service being stopped? Is this a quirk of win 7? A failing on my part to understand the ServiceController, or Win Services in general?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过进一步调查,我认为这是服务本身的问题。
After further investigation, I believe this is a problem with the service itself.