Pacman
Pacman

Reputation: 2245

Quartz.net with MVC

I am initializing Quartz inside my Application_Start() in Globals.asax.cs as followed:

// construct a scheduler factory
        ISchedulerFactory schedFact = new StdSchedulerFactory();
        IScheduler sched = schedFact.GetScheduler();
        sched.Start();

        IJobDetail dailyUserMailJob = new JobDetailImpl("DailyUserMailJob", null, typeof(DailyUserMail));
        // fire every daye
        ITrigger dailyUserMailTrigger = new SimpleTriggerImpl("DailyUserMailTrigger", 1,
                                                 new TimeSpan(1, 0, 0, 0));
        sched.ScheduleJob(dailyUserMailJob, dailyUserMailTrigger);

the Job should run once a day, the problem is, that it runs everytime I hit my website.

any ideas ?

Upvotes: 0

Views: 224

Answers (1)

David
David

Reputation: 218798

the Job should run once a day

Then it shouldn't be launched from a web application. It should be something like a console application that's run on a scheduler, or perhaps a Windows Service.

A web application is, by design, a request/response system. It's not suited for ongoing background tasks or scheduled offline tasks. Mainly because you have no control over when the application "starts" or "is running." The web server controls this when managing resources, and it can stop/restart the web application for any number of reasons.

Upvotes: 2

Related Questions