In this guide, you will learn how to create a basic scheduled task within Umbraco CMS V7. Umbraco has a built-in way of handling task scheduling. For one or two simple jobs that run every few hours, the built-in method is a great go-to tool. If you have more complex scheduling requirements, such as

  • You need the task to run at an exact time/date

  • You need a way to check completed without having to look within the Umbraco logs

  • The task you want to run needs to be locked down and the URL to access it cannot be public-facing

  • You have a high CPU long-running task

I suggest you look at using hangfire with Umbraco instead. Hangfire is great, it's free and it is feature-rich compared to the fairly basic Umbraco core alternative. I tend to use Hangfire on most projects and it is something I recommend! If my suggestion of Hangfire hasn't put you off and you still want to use the built-in scheduler, let us crack on!

Enabling A Task In Configuration

In your web root, open up config/umbracoSettings.config. About halfway down the file, you will see a section called scheduledTasks, as seen below:

This config section is where you can enable, configure and schedule your recurring tasks. Let us break down what each property in the config above does:

Log: Does what you think it would do, it turns on/off logging Alias: The name of the task, this can be anything you like * Interval: The frequency of how often the task will run. This is in seconds, so 86400 = 24hours, 3600 = 1 hour * URL: This is the action. The web address that will be called when the task is triggered. In this example, once every 24 hours a request to a page called www.mywebsite.com/settings/myscheduledtask will be made. With these four properties, we can create start scheduling!

Scheduled Task Code

In the config above a request is made to a page in your application. This means you will need to create an end-point. Typically you would create a custom MVC controller in your application to deal with this request. This controller could be a Umbraco based controller or a normal vanilla MVC controller. You will have to do the route handling yourself if you go the vanilla MVC route. In general, it will be easier to inherit from RenderMvcController instead. This process is the same as creating any vanilla MVC controller:

  • Create a class that inherits from Umbraco.Web.Mvc.RenderMvcController

  • Create an action

  • Return an appropriate HttpStatusCodeResult

Let's see a code example of what this controller might look like:

That is all you need to do! For a quick and dirty scheduled task, it is pretty simple to set up within Umbraco. Happy Coding 🤘