gpt4 book ai didi

c# - Quartz.net 作为服务无法配置 quartz_job.xml

转载 作者:太空宇宙 更新时间:2023-11-03 15:39:32 24 4
gpt4 key购买 nike

使用时

            var properties = new NameValueCollection();
properties["quartz.plugin.triggHistory.type"] = "Quartz.Plugin.History.LoggingJobHistoryPlugin";

properties["quartz.plugin.jobInitializer.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin";
properties["quartz.plugin.jobInitializer.fileNames"] = "quartz_jobs.xml";
properties["quartz.plugin.jobInitializer.failOnFileNotFound"] = "true";
properties["quartz.plugin.jobInitializer.scanInterval"] = "120";

// First we must get a reference to a scheduler
_schedulerFactory = new StdSchedulerFactory(properties);
_scheduler = _schedulerFactory.GetScheduler();

windows 服务/quartz 无法解析 quartz_jobs.xml 的路径。如果我将它作为控制台运行,它工作正常。

  public static void StartJobs()
{
try
{
_logger = LogManager.GetCurrentClassLogger();

var properties = new NameValueCollection();
properties["quartz.plugin.triggHistory.type"] = "Quartz.Plugin.History.LoggingJobHistoryPlugin";

properties["quartz.plugin.jobInitializer.type"] = "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin";
properties["quartz.plugin.jobInitializer.fileNames"] = "quartz_jobs.xml";
properties["quartz.plugin.jobInitializer.failOnFileNotFound"] = "true";
properties["quartz.plugin.jobInitializer.scanInterval"] = "120";

// First we must get a reference to a scheduler
_schedulerFactory = new StdSchedulerFactory(properties);
_scheduler = _schedulerFactory.GetScheduler();

// start the schedule
_scheduler.Start();
}
catch (Exception ex)
{
_logger.Error(ex);
throw new Exception(ex.Message);
}
}

最佳答案

如果仍然无法正常工作,请将该文件作为嵌入式资源包含在项目中,将操作设置为“始终复制”,以确保万无一失。然后提供 quartz 属性的完整文件路径:

Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "quartz_jobs.xml")

关于c# - Quartz.net 作为服务无法配置 quartz_job.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30712298/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com