Showing "Failed" for a SharePoint 2010 Timer Job Status

Posted by Damon on Simple Talk See other posts from Simple Talk or by Damon
Published on Mon, 05 Mar 2012 21:13:12 GMT Indexed on 2012/03/18 18:16 UTC
Read the original article Hit count: 204

Filed under:

I have been working with a bunch of custom timer jobs for last month.  Basically, I'm processing a bunch of SharePoint items from the timer job and since I don't want the job failing because of an error on one item, so I'm handing errors on an item-by-item basis and just continuing on with the next item.  The net result of this, I soon found, is that my timer job actually says it ran successfully even if every single item fails.  So I figured I would just set the "Failed" status on the timer job is anything went wrong so an administrator could see that not all was well.

However, I quickly found that there is no way to set a timer job status.  If you want the status to show up as "Failed" then the only way to do it is to throw an exception.  In my case, I just used a flag to store whether or not an error had occurred, and if so the the timer job throws a an exception just before existing to let the status display correctly.

© Simple Talk or respective owner