Windows 服务如何以编程方式自行重启?

编程入门 行业动态 更新时间:2024-10-28 08:31:23
本文介绍了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 服务如何以编程方式自行重启?

本文发布于:2023-11-03 13:36:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555251.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重启   方式   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!