如何在Sharepoint Timer作业中显示失败状态 [英] How to show Failed status in Sharepoint Timer Job

查看:101
本文介绍了如何在Sharepoint Timer作业中显示失败状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的计时器作业在某些情况下显示失败状态. 我应该抛出异常还是什么?

I want my timer job to display failed status on certain condition. Should I just throw an exception or what?

推荐答案

Hasan,

如果异常在代码中冒泡,则确实会显示失败状态.如果要使用计时器作业实例显式失败"运行,则可以并且应该抛出异常.如果您认为另一轮运行会绕过您的问题条件",则可以将SPJobDefinition.Retry标志值设置为 TRUE 来完成此操作.

If an exception bubbles out of the code, it will indeed show a failed status. If you want to explicitly "fail" your run with the timer job instance, you can and should throw an exception out. This can be done in conjunction with setting the SPJobDefinition.Retry flag value to TRUE if you feel that another run through would get around your "problem condition."

使用相同的标记,如果您出于日志记录目的而捕获异常(例如,将更多详细信息写到ULS日志中-绝对不是一个坏主意),请抛出所捕获的所有异常,除非您真正对其进行补偿.您要避免吃异常,只是为了避免由于某些原因使异常冒出来(异常状态与工作成功/失败报告相关).

By the same token, if you're trapping exceptions for logging purposes (e.g., to write additional detail out to the ULS logs -- never a bad idea), rethrow any exceptions you catch unless you truly compensate for them. You want to avoid eating exceptions just to avoid having exceptions bubble out for the reasons stated (exception status is tied to job success/failure reporting).

希望对您有帮助!

这篇关于如何在Sharepoint Timer作业中显示失败状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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