我是 Quartz.net 和编写 Windows 服务的完全菜鸟,所以如果这个问题有点不知情,我深表歉意。
无论如何,我设置了一个 Windows 服务来使用quartz.net 来运行另一个进行文件清理的Windows 服务。它安装和运行得很好(至少根据 installutil 和 net start 命令),但它从不向数据库添加任何内容。
我创建了数据库表和所有内容,数据库本身看起来很好。然后,我创建了一个 app.config,其中包含(我认为)我需要用来将这个东西连接到数据库的所有配置设置。但由于某种原因,数据库永远不会被触及。没有创建触发器(我显然是在代码中创建的),没有排队的作业,什么都没有。
它是一个 oracle 数据库,所有权限都设置为允许读/写和一切。
以下是 app.config 的源代码:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<quartz>
<add key="quartz.scheduler.instanceName" value="TestQuartzServer" />
<add key="quartz.scheduler.instanceId" value="instance_one" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.useProperties" value="false" />
<add key="quartz.jobStore.dataSource" value="default" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.clustered" value="true" />
<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.SimpleSemaphore, Quartz" />
<add key="quartz.dataSource.default.connectionStringName" value="ConnectionString" />
<add key="quartz.dataSource.default.provider" value="OracleClient-20" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" />
</quartz>
<connectionStrings>
<add name="ConnectionString" connectionString= "Server=localhost;Database=Quartz;Uid=Quartz;Pwd=Quartz" />
</connectionStrings>
</configuration>
这是应用程序源:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Triggers;
using System.Collections;
namespace PurgeScheduler1
{
public partial class Service1 : ServiceBase
{
public static IScheduler _scheduler;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try {
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
_scheduler = schedulerFactory.GetScheduler();
_scheduler.Start();
AddJob();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
protected override void OnStop()
{
}
public static void AddJob()
{
IJob myJob = new MyJob();
JobDetailImpl jobDetail = new JobDetailImpl("Purge", "Group1", myJob.GetType());
CronTriggerImpl trigger = new CronTriggerImpl("Trigger1", "Group1", "When to run it goes here");
SimpleTriggerImpl trigger1 = new SimpleTriggerImpl("Trigger2", 10, TimeSpan.FromMinutes(2));
_scheduler.ScheduleJob(jobDetail, trigger1);
DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc();
Console.WriteLine("Next Fire Time:" + nextFireTime.Value);
}
}
internal class MyJob : IJob
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("In myJob class");
Process.Start("correct path, but hiding it for proprietary reasons");
}
}
}