Quartz.Net embedded into Asp.NET MVC2, not firing off jobs

。_饼干妹妹 提交于 2019-12-02 03:00:00

问题


I'm trying to get Quartz.net working by embedding into my .Net MVC2 application. I know this is not ideal, but I'm just trying to get it up and running before moving it over to a service. I can't get my jobs to fire off, but I think I'm configured correctly. In my Global.asax.cs:

protected void Application_Start()
{
    Quartz.IScheduler scheduler = BuildQuartzScheduler();
    ... 
 }

And the method, taken straight from the tutorial:

private IScheduler BuildQuartzScheduler()
{
    // construct a scheduler factory
    ISchedulerFactory schedFact = new StdSchedulerFactory();

    // get a scheduler
    IScheduler sched = schedFact.GetScheduler();
    sched.Start();

    // construct job info
    JobDetail jobDetail = new JobDetail("myJob", null, typeof(QuartzController));
    // fire every hour
    Trigger trigger = TriggerUtils.MakeMinutelyTrigger();
    // start on the next even hour
    trigger.StartTimeUtc = TriggerUtils.GetEvenMinuteDate(DateTime.UtcNow);
    trigger.Name = "myTrigger";
    sched.ScheduleJob(jobDetail, trigger);
    return sched;
}

And the "controller:"

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

       public void Execute(JobExecutionContext context) {
           throw new NotImplementedException();
        }
    }

Nothing ever gets fired. What's going on? I'm sure there must be a simple syntax mistake, but it is driving me crazy!


回答1:


If Application_Start looks like that, then I reckon your scheduler variable is likely to be garbage collected as soon as that method finishes executing.

I'd store a reference to the scheduler as a static variable in your HttpApplication class. This way, the reference hangs around for the duration of the process. A guess, but worth a shot.



来源:https://stackoverflow.com/questions/3539995/quartz-net-embedded-into-asp-net-mvc2-not-firing-off-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!