Quartz.net的工作没有解雇

时间:2012-02-02 03:03:56

标签: c# quartz-scheduler scheduler

我已经使用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);
            }

        }
    }

1 个答案:

答案 0 :(得分:4)

您尚未启动调度程序:

sched.Start();