Schedular Application

Topics: Core, Customizing Orchard, Installing Orchard
May 5, 2015 at 3:02 PM
I want to write one schedular application in my current orchard solution. Can anyone help me out with where should I write the code and how should I write one schedular application.

I have found one code but cannot figure out where to paste this code?

public class MyTaskHandler : IScheduledTaskHandler
{
private const string TaskType = "MyTaskUniqueID";
private readonly IScheduledTaskManager _taskManager;

public ILogger Logger { get; set; }

public MyTaskHandler(IScheduledTaskManager taskManager)
{
_taskManager = taskManager;
Logger = NullLogger.Instance;
try
{
  DateTime firstDate = //Set your first task date (utc).
  ScheduleNextTask(firstDate);
}
catch(Exception e)
{
   this.Logger.Error(e,e.Message);
}
}

public void Process(ScheduledTaskContext context)
{
 if (context.Task.TaskType == TaskType)
 {
   try
   {
           //Do work (calling an IService for instance)
   }
   catch (Exception e)
   {
     this.Logger.Error(e, e.Message);
   }
   finally
   {
     DateTime nextTaskDate = //Your next date (utc).
     this.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);
  }
}


}



Please help!!!