Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Viewing all articles
Browse latest Browse all 286

Sitecore start scheduled task manually

$
0
0

Sitecore scheduled tasks are background tasks running on a schedule. But never when you need it, especially when developing the tasks. You can trigger these tasks manually if you please.

THE EASY WAY: INSTALL SITECORE POWERSHELL

The Sitecore PowerShell module have a built in task runner. When installed, you can right click the task you wish to run and click “Run Task Schedule

Powrshell Run Task

Powrshell Run Task

THE FUN WAY: PROGRAM YOUR OWN TASK STARTER:

You can, of course, write your own task runner, create a nice scheduled task page, and display all possible tasks where you can start them individually:

Scheduled Tasks List

Scheduled Tasks List

To get a list of all scheduled tasks:

private const string SCHEDULED_PATH = "/sitecore/system/Tasks//*[@@templatename='Schedule']";
  
foreach (Item item in Sitecore.Context.Database
  .SelectItems(SCHEDULED_PATH)
  .OrderBy(t => t.Parent.Name)
  .ThenBy(t => t.Name))
{
  ScheduleItem scheduleItem = new ScheduleItem(item);
  // Do stuff with the scheduleItem
}

To start a scheduled task:

Sitecore.Tasks.ScheduleItem scheduleItem = new Sitecore.Tasks.ScheduleItem(item);
scheduleItem.Execute();

MORE TO READ:


Viewing all articles
Browse latest Browse all 286

Trending Articles