A simple ASP.NET task scheduler.
To create a task, simply create a class that implements IScheduledTask.
public class GenericTask : IScheduledTask
{
public void DoWork()
{
// do something
}
}
To initialize the task (which is usually done when the application starts), invoke the scheduler with an instance of a schedule (you can use a default schedule, or create a schedule of your own).
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Scheduler.Schedule<GenericTask>(new Daily(3, 30, "Eastern Standard Time"));
}
}
To create a new schedule, create a class that implements ISchedule.
public class Interval : ISchedule
{
private long _seconds;
public Interval(long seconds)
{
_seconds = seconds;
}
public DateTime GetUtcExpirationDate()
{
return DateTime.UtcNow.AddSeconds(_seconds);
}
}