开发者

Quartz .NET doesn't fire trigger, Why?

I'm using Quartz in my .NET application. At first, I was using it in a windows service but it didn't work, so I moved it to a normal project to test it. This is the code in Main:

ISchedulerFactory schedFact = new StdSchedulerFactory();
IScheduler sched = schedFact.GetScheduler();
JobDetai开发者_开发问答l jobDetail = new JobDetail("JobPrueba", null, typeof(JobPrueba));
Trigger trigger = TriggerUtils.MakeMinutelyTrigger(1, 3);
trigger.StartTimeUtc = DateTime.Now;
trigger.Name = "TriggerPrueba";
sched.Start();
sched.ScheduleJob(jobDetail, trigger);

and this is JobPrueba:

class JobPrueba : IStatefulJob
{
    public JobPrueba() { }

    public void Execute(JobExecutionContext context)
    {
        const string fic = @"C:\prueba.txt";
        string texto = DateTime.Now.ToString();
        System.IO.StreamWriter sw = new System.IO.StreamWriter(fic, true);
        sw.WriteLine(texto);
        sw.Close();
        System.Console.WriteLine("Hello world");
    }
}

It's not doing anything at all, when last line in Main is executed, the program never ends, but it doesn't write in file nor print Hello World in console.

Does anyone know what I am doing wrong?


I've discovered that it's a problem of times. I live in a country which time is UTC + 2, so when I set the StartTimeUtc of the trigger to DateTime.Now, instead of UtcNow, the trigger didn't have to fire until two hours later, and I thought it has to fire in the very moment the code was executed.

Besides, I set a timer in order to log what was happening, and in that log I printed current time (with DateTime.Now) and the StartTimeUtc of the trigger, and obviously they were the same and later DateTime.Now was greater than StartTimeUtc. If I had printed DateTime.UtcNow I had seen the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜