0

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 ?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I am hosting my website on a shared host, I am unable to do that, what other ways I can accomplish this ?
@Pacman: I suppose you could keep a database record that indicates if the process has already run for the current day and check against that record before running the process from the web application. You'd have to remember to trigger it from the web application every day, though. The bottom line is that web applications aren't suited for running scheduled jobs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.