Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listening to task scheduler events in c#

Have a list of tasks and their schedules. Say Task1 - Daily 12 PM Task2 - Monday, Wednesday - 9 PM Would like to fire them as per their schedules.

Is it possible to register them with task scheduler or some other scheduler\timers in c# with unique context - the task id. And on call back (say some event), can get the taskid from the context and using the taskid, i can trigger of the actions.

Basically need call back when the scheduled time has been met with the context which has been passed. And my code knows the best, what has to be done during that scheduled time.

like image 779
KrishnaSrihari Avatar asked Nov 16 '12 08:11

KrishnaSrihari


Video Answer


1 Answers

Why don't you try using quartz.net. This scheduler support task Id and even context of scheduling. There is also good documentation and lots of examples.

Here is the example of task(aka Job), context of executing is send from scheduler.

public class DumbJob : IJob
{
    public DumbJob() {
    }

    public void Execute(JobExecutionContext context)
    {
        Console.WriteLine("DumbJob is executing.");
    }
}

BTW don't forget to make scheduler static - to avoid being garbage collected. I've already met this problem before.

like image 76
Johnny_D Avatar answered Sep 21 '22 23:09

Johnny_D