Scheduled task

Scheduled tasks, which are classes that implement the quite simple IScheduledTaskHandler interface allow you to run some code at a specific time (Orchard will respect it with a 1-minute precision). The way of creating a scheduled task is to first create an IScheduledTaskHandler implementation and put your code inside the only method in this interface called Process. Using the IScheduledTaskManager service, you can create, list and delete scheduled tasks, so in order to register your scheduled task in Orchard, you need to create it first using the CreateTask method. Orchard uses a background task to check for scheduled tasks that should be executed: each scheduled task is stored in the database as a separate record which is deleted when the execution of the given task starts to make sure that they only run once. Please also note that scheduled tasks must have a unique name: according to the Orchard naming best practices, it is advised to prefix it with the name of your module.

For more information please see the Visual Studio code snippet related to scheduled tasks (a simple and a renewing one, the latter depends on the Piedone.HelpfulLibraries module) and a definite guide on how to create one in the Orchard Training Demo module.

This page is part of the Orchard Dojo Library!

This page and many others here are part of the open-source, portable package of Orchard 1.x goodies: the Orchard Dojo Library for Orchard 1.x. The Library is freely accessible by anyone; just go to its repository to download its full content (you can even download the textual content of the Library as a big concatenated document in HTML), file issues or fork it! You can even edit it online on Bitbucket, just click on the Edit link in the upper right corner!

Note that the Library also has an Orchard Core version, check it out here!