【问题标题】:Quartz.net job not firingQuartz.net 作业未触发
【发布时间】:2012-02-02 03:03:56
【问题描述】:

我已经使用 Quartz.net 设置了一个 cron 作业,但它似乎没有触发。

上传后,我对 web.config 进行了更改以重新启动应用程序,因此它应该运行 Application_Start 方法。我还使用一个简单的触发器测试了 Job,它可以工作,所以我不确定发生了什么。

 void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        // 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(Recorder));
        jobDetail.JobDataMap["domain"] = "www.mydomain.com";
        jobDetail.JobDataMap["userId"] = "2";

        // Create trigger (everything is in UTC!!!)
        CronTrigger cronTrigger = new CronTrigger("Schedule");
        cronTrigger.StartTimeUtc = TriggerUtils.GetEvenSecondDate(DateTime.UtcNow);
        cronTrigger.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");  // run in pacific timezone
        cronTrigger.CronExpressionString = "0 30 13 ? * MON-FRI *"; 

        sched.ScheduleJob(jobDetail, cronTrigger);
    }





    public class Recorder : IJob
    {

        public void Execute(JobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            string domain = dataMap.GetString("domain");
            string userId = dataMap.GetString("userId");

            string url = "http://" + domain + "/record.aspx?userId=" + userId;

            using (WebClient client = new WebClient())
            {
                client.DownloadString(url);
            }

        }
    }

【问题讨论】:

    标签: c# quartz-scheduler scheduler


    【解决方案1】:

    您尚未启动调度程序:

    sched.Start();
    

    【讨论】:

    • 显然他在第9行使用过
    • 确实,帖子中没有编辑。可能是因为它需要在配置计划后开始。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    相关资源
    最近更新 更多