I have to run a automated job every 5 hours. 

I found this post on how to create scheduled tasks, using IScheduledTaskHandler and IScheduledTaskManager. 
[Scheduled tasks using Orchard CMS](https://stackoverflow.com/questions/8916146/scheduled-tasks-using-orchard-cms)

I copied the same code, I added my service call inside the Process function. It compiles fine. But I am not sure if I have to 'start' this scheduled task, like a windows service start. Does it get picked up automatically after I build the solution? When does the clock starts ticking if I want to run this job in 5 hours? And if I want to stop/pause, how can I do that?

Thanks.

EDIT:

I am getting an exception if I try to enable the custom module with task handler. 

Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: source

```
Line 241: var shellContext = _shellContexts.FirstOrDefault(c => c.Settings.Name == settings.Name);

```

Source File: \orchard-1.4\src\Orchard\Environment\DefaultOrchardHost.cs Line: 241 

The \_shellContexts is coming up as null. If I remove the task handler class from the project/module, everything works fine.

Here is the task handler code.

```
public class ScheduledTaskHandler : IScheduledTaskHandler
{
    private const string TaskType = "MyTaskUniqueID";
    private readonly IScheduledTaskManager _taskManager;
    private readonly IMyService _myService;

    public ILogger Logger { get; set; }

    public ScheduledTaskHandler(IScheduledTaskManager taskManager, IMyService myService)
    {
        _myService = myService;
        _taskManager = taskManager;
        Logger = NullLogger.Instance;
        try
        {
            DateTime firstDate = new DateTime().AddMinutes(5);
            ScheduleNextTask(firstDate);
        }
        catch (Exception e)
        {
            this.Logger.Error(e, e.Message);
        }
    }

    public void Process(ScheduledTaskContext context)
    {
        if (context.Task.TaskType == TaskType)
        {
            try
            {
                _myService.RunJob();
            }
            catch (Exception e)
            {
                this.Logger.Error(e, e.Message);
            }
            finally
            {
                DateTime nextTaskDate = new DateTime().AddHours(5);
                ScheduleNextTask(nextTaskDate);
            }
        }
    }

    private void ScheduleNextTask(DateTime date)
    {
        if (date > DateTime.UtcNow)
        {
            var tasks = this._taskManager.GetTasks(TaskType);
            if (tasks == null || tasks.Count() == 0)
                this._taskManager.CreateTask(TaskType, date, null);
        }
    }

}

```