异常在Windows服务处理的最佳实践? [英] Exception handling best practice in a windows service?

查看:158
本文介绍了异常在Windows服务处理的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写的完全是在后台运行,每天做了一个窗口服务。我的想法是,服务应该是很稳定,所以如果出现问题,应该不会停止,但再次尝试第二天,当然记录异常。你可以建议我任何的最佳实践如何使真正稳定的Windows服务?

I am currently writing a windows service that runs entirely in the background and does something every day. My idea is that the service should be very stable so if something goes wrong it should not stop but try it next day again and of course log the exception. Can you suggest me any best practice how to make truly stable windows services?

我看过异常斯科特Hanselman的处理最佳实践的文章他写道,目前只有少数情况下时,你应该吞下一个例外。我觉得莫名其妙的Windows服务是为数不多的案例之一,但我很乐意得到一些证实。

I have read the article of Scott Hanselman of exception handling best practice where he writes that there are only few cases when you should swallow an exception. I think somehow that windows service is one of the few cases, but I would be happy to get some confirmation on that.

推荐答案

吞咽一个例外是放弃一个特定的任务而无需停止整个进程的不同。
在我们的windows服务,我们捕捉异常,记录他们的详细信息,然后优雅降级的任务,等待下一个任务。然后我们可以使用日志来解决,而服务器仍在运行的错误。

'Swallowing' an exception is different to 'abandoning a specific task without stopping the entire process'. In our windows service, we catch exceptions, log their details, then gracefully degrade that task and wait for the next task. We can then use the log to troubleshoot the error while the server is still running.

这篇关于异常在Windows服务处理的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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