如何在.NET中以编程方式重新启动Windows服务 [英] How can I restart a windows service programmatically in .NET

查看:104
本文介绍了如何在.NET中以编程方式重新启动Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在.NET中以编程方式重新启动Windows服务?

另外,我需要在服务重启完成后执行一项操作。

How can I restart a windows service programmatically in .NET?
Also, I need to do an operation when the service restart is completed.

推荐答案

看看 ServiceController 类。

执行服务需要执行的操作重新启动后,我想您应该在服务中自己进行操作(如果它是您自己的服务)。

如果您没有访问服务源的权限,那么也许可以使用< ServiceController 的code> WaitForStatus 方法。

To perform the operation that needs to be done when the service is restarted, I guess you should do that in the Service yourself (if it is your own service).
If you do not have access to the source of the service, then perhaps you can use the WaitForStatus method of the ServiceController.

这篇关于如何在.NET中以编程方式重新启动Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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