Windows 服务如何以编程方式自行重启? [英] How can a windows service programmatically restart itself?

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

问题描述

我需要在 .NET 中编写健壮的代码以启用 Windows 服务(服务器 2003)来重新启动.这样做的最佳方法是什么?是否有一些 .NET API 可以做到这一点?

I need to write robust code in .NET to enable a windows service (server 2003) to restart itself. What is the best way to so this? Is there some .NET API to do it?

推荐答案

将服务设置为失败后重新启动(双击控制面板中的服务并查看这些选项卡 - 我忘记了它的名称).然后,只要您希望服务重新启动,只需调用 Environment.Exit(1)(或任何非零返回),操作系统就会为您重新启动它.

Set the service to restart after failure (double click the service in the control panel and have a look around on those tabs - I forget the name of it). Then, anytime you want the service to restart, just call Environment.Exit(1) (or any non-zero return) and the OS will restart it for you.

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

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