Quartz.Net 嵌入到 Asp.NET MVC2 中,而不是触发作业

发布于 2024-09-15 10:07:34 字数 1240 浏览 2 评论 0原文

我试图通过嵌入到我的 .Net MVC2 应用程序中来让 Quartz.net 工作。我知道这并不理想,但我只是想在将其转移到服务之前将其启动并运行。我无法启动我的工作,但我认为我的配置正确。在我的 Global.asax.cs 中:

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

以及直接取自教程的方法:

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;
}

以及“控制器:”

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

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

没有任何东西被解雇。这是怎么回事?我确信一定有一个简单的语法错误,但这让我发疯!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉酒的小男人 2024-09-22 10:07:34

如果 Application_Start 看起来像这样,那么我认为您的 scheduler 变量可能会在该方法完成执行后立即被垃圾收集。

我将对 scheduler 的引用存储为 HttpApplication 类中的静态变量。这样,引用就会在整个过程中一直存在。一个猜测,但值得一试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文