可以用.NET编写服务自终止? [英] Can a service written in .NET self-terminate?

查看:107
本文介绍了可以用.NET编写服务自终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#编写,并在某些情况下服务应用程序,我想它终止自己。这将服务已运行一段时间后发生的,所以这不会在的OnStart()事件发生。

I have a service application written in C# and under certain circumstances, I would like it to terminate itself. This would happen after the service has been running for a while, so this would not be happening in the OnStart() event.

一切,我已经阅读迄今表明,终止服务的唯一安全的方法是通过服务控制管理器。我的服务作为本地服务,没有启动或停止服务的权利,所以我不能从服务本身访问SCM。有另一种方式自我终结,同时仍然由单片机的规则玩?

Everything that I have read so far suggests that the only safe way to terminate a service is through the Service Control Manager. My service runs as Local Service and does not have the rights to start or stop services, so I can't access the SCM from the service itself. Is there another way to self-terminate while still playing by the rules of the SCM?

推荐答案

尝试的 ServiceBase.Stop()

这篇关于可以用.NET编写服务自终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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