We have two scheduled tasks and the requirement is to make them run at the same time everyday. One of them is Async
(Task1) and the other Non-Async
(Task2).
Sitecore by default, auto updates its Last Run
field after a task is completed, and for this reason, tasks do not run at the same time everyday. For this to happen, an alternative is to update the Last Run
field's value to our desired DateTime.
I was able to achieve this for the Async
task, by following this article.
The trick is to have a try-catch
statement and keep the update code inside the finally
block.
private void MethodForAsyncTask()
{
try
{
//code to get some data
}
catch
{
}
finally
{
//code to update the last run field value
}
}
This works only if the task is Async. Because, code in the finally
block gets executed after Sitecore updates the Last run field. All good.
But now, I need to know, how can I do this for a synchronous task, i.e updating the Last Run field value after the task is completed.
One idea I had, was to create another scheduled task to run for every 1 minute and update the Last Run field value of Task2. But how do I know if the task2 was successfully completely today.
using Sitecore v8.0 Update-5