Tuesday, February 16, 2010

Simple task Scheduling using Global.asax

The article below describes very simple task scheduling by just using Global.asax.

http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax

However, I had changed the approach slightly because I didn't  want to rely on Session_Start() event and execute my code unnecessarily. Below you find another simple example with Timer control.

private static Timer ScheduledTaskTimer = new Timer();

void Application_Start(object sender, EventArgs e){

      ScheduledTaskTimer.Elapsed += new ElapsedEventHandler(ScheduledTaskTimer_Elapsed);

       ScheduledTaskTimer.Interval = 1 * 60 * 60 * 24;

    ScheduledTaskTimer.Enabled = true;

}

static void ScheduledTaskTimer_Elapsed(object sender, ElapsedEventArgs e)

        {

            //your scheduled task logic goes here.

        }

Technorati Tags: ,,,

No comments: