C# 在Quartz.net中解耦角色

C# 在Quartz.net中解耦角色,c#,scheduled-tasks,scheduling,quartz.net,C#,Scheduled Tasks,Scheduling,Quartz.net,我目前正在研究使用Quartz.NET在我的系统中调度任务。作为我如何使用Quartz.NET的示例,下面是一个非常简单的示例,演示我如何安排任务: class Program { static void Main(string[] args) { var properties = new NameValueCollection(); properties["quartz.scheduler.instanceName"] = "TestSchedu

我目前正在研究使用Quartz.NET在我的系统中调度任务。作为我如何使用Quartz.NET的示例,下面是一个非常简单的示例,演示我如何安排任务:

class Program
{
    static void Main(string[] args)
    {
        var properties = new NameValueCollection();
        properties["quartz.scheduler.instanceName"] = "TestScheduler";
        properties["quartz.scheduler.instanceId"] = "instance_one";
        properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
        properties["quartz.jobStore.useProperties"] = "true";
        properties["quartz.jobStore.dataSource"] = "default";
        properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
        properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
        properties["quartz.dataSource.default.connectionString"] = "Server=.\\SqlExpress;Database=quartz;Trusted_Connection=True;";
        properties["quartz.dataSource.default.provider"] = "SqlServer-20";

        var scheduler = new StdSchedulerFactory(properties).GetScheduler();

        scheduler.Start();

        TriggerSimpleJob(scheduler);

        Console.WriteLine("Waiting For Job");
        Console.ReadLine();
    }

    private static void TriggerSimpleJob(IScheduler scheduler)
    {
        ITrigger trigger = TriggerBuilder.Create()
                              .WithIdentity("trigger1", "group1")
                              .StartAt(DateBuilder.EvenSecondDateAfterNow())
                              .UsingJobData("myTriggerParameter", "myTriggerValue")
                              .UsingJobData("myParameter", "triggerParameter")
                              .Build();

        IJobDetail jobDetail = JobBuilder.Create<SimpleJob>().WithIdentity("job1", "group1")
            .UsingJobData("myParameter", "myValue")
            .Build();

        scheduler.ScheduleJob(jobDetail, trigger);
    }
}

public class SimpleJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
       Console.WriteLine("Job completed");
    }
}
类程序
{
静态void Main(字符串[]参数)
{
var properties=new NameValueCollection();
属性[“quartz.scheduler.instanceName”]=“TestScheduler”;
属性[“quartz.scheduler.instanceId”]=“实例一”;
属性[“quartz.jobStore.type”]=“quartz.Impl.AdoJobStore.JobStoreTX,quartz”;
属性[“quartz.jobStore.useProperties”]=“true”;
属性[“quartz.jobStore.dataSource”]=“默认值”;
属性[“quartz.jobStore.tablePrefix”]=“QRTZ_”;
属性[“quartz.jobStore.lockHandler.type”]=“quartz.Impl.AdoJobStore.UpdateLockRowSemaphore,quartz”;
属性[“quartz.dataSource.default.connectionString”]=“Server=。\\SqlExpress;Database=quartz;Trusted_Connection=True;”;
属性[“quartz.dataSource.default.provider”]=“SqlServer-20”;
var scheduler=new StdSchedulerFactory(properties).GetScheduler();
scheduler.Start();
TriggerSimpleJob(调度程序);
Console.WriteLine(“等待作业”);
Console.ReadLine();
}
私有静态无效触发器SimpleJob(ISScheduler调度器)
{
ITrigger trigger=TriggerBuilder.Create()
.WithIdentity(“触发器1”、“组1”)
.StartAt(DateBuilder.EvenSecondDateAfterNow())
.使用JobData(“myTriggerParameter”、“myTriggerValue”)
.使用JobData(“myParameter”、“triggerParameter”)
.Build();
IJobDetail jobDetail=JobBuilder.Create().WithIdentity(“job1”、“group1”)
.使用JobData(“myParameter”、“myValue”)
.Build();
ScheduleJob(作业详细信息,触发器);
}
}
公共类SimpleJob:IJob
{
public void Execute(IJobExecutionContext上下文)
{
Console.WriteLine(“作业已完成”);
}
}
我的问题是:

我想将作业调度与作业执行分离。

在上面的示例中,在调度作业后,如果在调度时间到达时流程仍在运行,则作业将在此流程内执行。理想情况下,我希望能够有一个专用服务器,其中运行一个专用于执行作业的Quartz.NET调度程序实例,并且能够从其他进程调度作业,知道作业将在此专用服务器上执行

我尝试在调度作业的进程上将属性“quartz.threadPool.threadCount”设置为“0”,但这会引发异常。调度程序上是否有任何配置属性可以实现我尝试执行的操作?

早上好

你可以读我的答案

我的建议是使用(看起来你正在使用它)。 应配置负责调度作业的应用程序,将属性threadPool设置为ZeroSizeThreadPool

properties["quartz.threadPool.type"] = "Quartz.Simpl.ZeroSizeThreadPool, Quartz";
您可以阅读有关这种类型的线程池的更多信息

负责执行作业的应用程序应配置以下设置:

properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "10";
properties["quartz.threadPool.threadPriority"] = "Normal";
早上好

你可以读我的答案

我的建议是使用(看起来你正在使用它)。 应配置负责调度作业的应用程序,将属性threadPool设置为ZeroSizeThreadPool

properties["quartz.threadPool.type"] = "Quartz.Simpl.ZeroSizeThreadPool, Quartz";
您可以阅读有关这种类型的线程池的更多信息

负责执行作业的应用程序应配置以下设置:

properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "10";
properties["quartz.threadPool.threadPriority"] = "Normal";
拆下线路

 scheduler.Start();
拆下线路

 scheduler.Start();

完美-正是我想要的。谢谢。太好了——正是我想要的。谢谢