c# – Topshelf在第三次尝试后停止服务恢复
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Topshelf在第三次尝试后停止服务恢复,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2057字,纯文字阅读大概需要3分钟。
内容图文
![c# – Topshelf在第三次尝试后停止服务恢复](/upload/InfoBanner/zyjiaocheng/782/34440419826e4b27a7f8b80882c721f6.jpg)
我正在使用Topshelf来创建Windows服务.此服务将尝试恢复前3个故障,但在此之后,它将不再起作用.
检查主机上的服务中的服务显示:
First Failure: Restart the Service
Second Failure: Restart the Service
Subsequent Failures: Restart the Service
Reset fail count after: 1 days
Restart service after: 2 minutes
服务恢复代码如下所示:
f.EnableServiceRecovery(r =>
{
r.RestartService(2);
r.RestartService(5);
r.RestartService(5);
r.OnCrashOnly();
r.SetResetPeriod(1);
});
检查事件日志会在恢复失败后显示以下消息:
The MyService service terminated unexpectedly. It has done this 1 time(s). The following corrective action will be taken in 120000 milliseconds: Restart the service.
The MyService service terminated unexpectedly. It has done this 2 time(s). The following corrective action will be taken in 300000 milliseconds: Restart the service.
The MyService service terminated unexpectedly. It has done this 3 time(s). The following corrective action will be taken in 300000 milliseconds: Restart the service.
The MyService service terminated unexpectedly. It has done this 4 time(s).
从上面可以明显看出.第四次不会触发恢复.
这是Windows错误,Topshelf问题,还是我的配置有问题?
解决方法:
您必须为topshelf恢复设置设置底部配置:
x.EnableServiceRecovery(rc =>
{
// Has no corresponding setting in the Recovery dialogue.
// OnCrashOnly means the service will not restart if the application returns
// a non-zero exit code. By convention, an exit code of zero means ‘success’.
rc.OnCrashOnly();
// Corresponds to ‘First failure: Restart the Service’
// Note: 0 minutes delay means restart immediately
rc.RestartService(delayInMinutes: 0);
// Corresponds to ‘Second failure: Restart the Service’
// Note: TopShelf will configure a 1 minute delay before this restart, but the
// Recovery dialogue only shows the first restart delay (0 minutes)
rc.RestartService(delayInMinutes: 1);
// Corresponds to ‘Subsequent failures: Restart the Service’
rc.RestartService(delayInMinutes: 5);
// Corresponds to ‘Reset fail count after: 1 days’
rc.SetResetPeriod(days: 1);
});
看看sample
内容总结
以上是互联网集市为您收集整理的c# – Topshelf在第三次尝试后停止服务恢复全部内容,希望文章能够帮你解决c# – Topshelf在第三次尝试后停止服务恢复所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。