如何在 Sharepoint 计时器作业中显示失败状态

发布于 2024-08-06 23:42:08 字数 43 浏览 4 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-08-13 23:42:08

Hasan,

如果代码中出现异常,它确实会显示失败状态。如果您想显式地使计时器作业实例的运行“失败”,您可以而且应该抛出异常。如果您认为另一次运行可以解决您的“问题情况”,则可以结合将 SPJobDefinition.Retry 标志值设置为 TRUE 来完成此操作。

出于同样的原因,如果您出于记录目的而捕获异常(例如,将额外的详细信息写入 ULS 日志 - 这绝不是一个坏主意),请重新抛出您捕获的任何异常,除非您真正补偿了它们。您希望避免吃掉异常,只是为了避免由于所述原因而出现异常(异常状态与作业成功/失败报告相关)。

我希望这有帮助!

Hasan,

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."

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).

I hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文