我得到了一个 ASP.NET MVC 4 Web 应用程序和作为 Windows 服务运行的quartz.net,并根据这些来源配置了通用日志记录:
并在 Global.asax 中使用此代码:
var properties = new NameValueCollection();
properties["quartz.scheduler.instanceName"] = "ServerScheduler";
// set thread pool info
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "5";
properties["quartz.threadPool.threadPriority"] = "Normal";
// set remoting expoter
properties["quartz.scheduler.proxy"] = "true";
properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory(properties);
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
IJobDetail jobDetail = JobBuilder.Create<SimpleJob>()
.WithIdentity("simpleJob", "simpleJobs")
.RequestRecovery()
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("simpleTrigger", "simpleTriggers")
.StartNow()
.WithSimpleSchedule(x => x.WithRepeatCount(4).WithIntervalInSeconds(10))
.Build();
sched.ScheduleJob(jobDetail, trigger);
和工作:
public class SimpleJob : IJob
{
public SimpleJob()
{
}
public void Execute(IJobExecutionContext context)
{
Debug.WriteLine("I Executed at " + DateTime.Now.ToString());
}
}
现在如果我运行应用程序,日志会产生这样的 5 次
19:35:23 [ServerScheduler_QuartzSchedulerThread] DEBUG Quartz.Core.QuartzSchedulerThread - Batch acquisition of 1 triggers
19:35:23 [ServerScheduler_QuartzSchedulerThread] DEBUG Quartz.Simpl.SimpleJobFactory - Producing instance of Job 'simpleJobs.simpleJob', class=Navigate.Quartz.Jobs.SimpleJob
19:35:23 [ServerScheduler_QuartzSchedulerThread] DEBUG Quartz.Core.QuartzSchedulerThread - Batch acquisition of 1 triggers
19:35:23 [ServerScheduler_Worker-1] DEBUG Quartz.Core.JobRunShell - Calling Execute on job simpleJobs.simpleJob
19:35:23 [ServerScheduler_Worker-1] DEBUG Quartz.Core.JobRunShell - Trigger instruction : NoInstruction
然后删除触发器并继续,但没有执行任何作业,也没有将行写入调试输出
但是,如果我运行嵌入在应用程序中的调度程序,则不将 NameValueCollection 传递给 StdSchedulerFactory
ISchedulerFactory schedFact = new StdSchedulerFactory();
一切正常,我每 10 秒输出 5 次行
I Executed at 28.05.2013. 19:47:48
I Executed at 28.05.2013. 19:47:58
I Executed at 28.05.2013. 19:48:08
I Executed at 28.05.2013. 19:48:18
I Executed at 28.05.2013. 19:48:28
我错过了什么,为什么 Windows 服务没有实际执行代码,该服务作为本地系统运行,如果我将其更改为管理员帐户,则没有任何变化。任何帮助将不胜感激。
克里斯