c# - Quartz.NET 远程处理 - 调度程序已经存在

标签 c# quartz-scheduler quartz.net

我正在创建一个使用 Quartz.NET 的应用程序,它在 Windows 服务中使用。还有一个用 ASP.NET 编写的管理后端,管理员可以在其中添加作业并监视调度程序的状态。但是,我在 ASP.NET 后端遇到问题。

连接是在 Global.asax 文件中建立的,起初似乎可以正常工作 - 当用户登录到主仪表板时,它可以正常工作。问题是当用户点击另一个页面时,它会说调度程序“schedService”已经存在。

这是我的 Windows 服务代码:

NameValueCollection properties = new NameValueCollection();

properties["quartz.scheduler.instanceName"] = "schedService";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = threadcount;
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.jobStore.misfireThreshold"] = "60000";
properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
properties["quartz.jobStore.useProperties"] = "false";
properties["quartz.jobStore.dataSource"] = "default";
properties["quartz.jobStore.tablePrefix"] = "QRTZ_";

//
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "555";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";

//
// if running MS SQL Server we need thisl
properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";

// config file
properties["quartz.dataSource.default.connectionString"] = connection;
properties["quartz.dataSource.default.provider"] = "SqlServer-20";

ISchedulerFactory schedService = new StdSchedulerFactory(properties);
IScheduler sched = schedService.GetScheduler();

ASP.NET Global.asax 代码:

public static IScheduler Sched()
{
    NameValueCollection properties = new NameValueCollection();

    properties["quartz.scheduler.instanceName"] = "schedMaintenanceService";

    properties["quartz.scheduler.proxy"] = "true";
    properties["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";

    ISchedulerFactory sf = new StdSchedulerFactory(properties);
    IScheduler sched = sf.GetScheduler();
    return sched;
}

然后我在每个 ASP.NET 页面中使用它:

public static IScheduler sched = Project.Global.Sched();

最佳答案

你应该把你的 IScheduler 写成单例

关于c# - Quartz.NET 远程处理 - 调度程序已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4594742/

相关文章:

c# - 如何使用 lambda 运算符修改此 linq 查询?

c# - 什么是 MVC future 库?

java - GlassFish 上 Quartz 计划的 JSR-352 作业无法启动

quartz-scheduler - 通过配置文件和构造函数的混合来配置 Quartz.NET

c# - Quartz.Net 2.0.1 触发器

c# - 无法在 SQL Server 2012 中创建数据库

c# - 从 C# Winform 连接到 MS Access 数据库时出错

c# - 如何为 Controller 创建我自己的 http 上下文?

java - quartz spring集成调度,是否可以动态设置cron触发器

Quartz 失败的 Azure Web 作业