您需要在 app.config/web.config 中定义一个 ADOJobStore,然后是一些quartz.config。我叫我的 QuartzDataStoreSettingsDatabase.config
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<quartz configSource="QuartzDataStoreSettingsDatabase.config" />
然后是石英特定材料的文件
QuartzDataStoreSettingsDatabase.config
<quartz>
<add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzSchedulerFromConfigFileSqlServer"/>
<add key="quartz.scheduler.instanceId" value="instance_one"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="Normal"/>
<!--
org.quartz.scheduler.idleWaitTime
Is the amount of time in milliseconds that the scheduler will wait before re-queries for available triggers when the scheduler is otherwise idle. Normally you should not have to 'tune' this parameter, unless you're using XA transactions, and are having problems with delayed firings of triggers that should fire immediately.
It defaults to every 30 seconds until it finds a trigger. Once it finds any triggers, it gets the time of the next trigger to fire and stops checking until then, unless a trigger changes. -->
<add key="quartz.scheduler.idleWaitTime" value ="5000"/>
<!-- Misfire : see http://nurkiewicz.blogspot.com/2012/04/quartz-scheduler-misfire-instructions.html -->
<add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/>
<add key="quartz.jobStore.tablePrefix" value="QRTZ_"/>
<add key="quartz.jobStore.clustered" value="false"/>
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"/>
<add key="quartz.jobStore.dataSource" value="MySqlServerFullVersion"/>
<add key="quartz.jobStore.useProperties" value="false"/>
<add key="quartz.dataSource.MySqlServerFullVersion.connectionString" value="SuperSecret!!"/>
<add key="quartz.dataSource.MySqlServerFullVersion.provider" value="SqlServer-20"/>
</quartz>
在这里查看我的答案:
Unable to save anything to the Quartz.net ado store
然后,当您的网站世界中发生“事件”时......您需要以编程方式安排工作。
NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");
ShowConfiguration(config, logger);
ISchedulerFactory factory = new StdSchedulerFactory(config);
IScheduler sched = factory.GetScheduler();
/* the below code has to be tweaked for YOUR Job */
IJobDetail textFilePoppingJobJobDetail = JobBuilder.Create<TextFilePoppingNonConcurrentJob>()
.WithIdentity("textFilePoppingJobJobDetail001", "groupName007")
.UsingJobData("JobDetailParameter001", "Abcd1234")
.Build();
ITrigger textFilePoppingJobJobDetailTrigger001 = TriggerBuilder.Create()
.WithIdentity("textFilePoppingJobJobDetailTrigger001", "groupName007")
.UsingJobData("TriggerParameter001", "Bcde2345")
.UsingJobData("TempDirectorySubFolderName", "MyTempDirectorySubFolderName")
.UsingJobData("DestinationFullFolderName", @"C:\SomeFolder")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.RepeatForever()
/* .WithRepeatCount(1) */
)
.Build();
sched.ScheduleJob(textFilePoppingJobJobDetail, textFilePoppingJobJobDetailTrigger001);