在使用时
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);
}
}发布于 2015-06-09 00:50:03
如果它仍然不起作用,请将该文件作为嵌入式资源包含在项目中,并将操作设置为始终复制,以确保这一点。然后提供quartz属性的完整文件路径:
Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "quartz_jobs.xml")发布于 2019-01-17 05:50:43
我知道这个帖子来自2015年,但我找不到任何关于在windows服务中使用quartz.net的信息。在我的例子中,我使用.Net Core2.1通用主机作为windows服务,并使用在我的appsettings.json文件中引用的quartz_jobs.xml。当windows服务启动并查找quartz_job.xml时,它会尝试在c:\windows\system32中找到它。但是我的quartz_job.xml位于我的可执行文件所在的位置。我在他们的存储库的Quaztz\Util\FileUtil.cs中找到了方法ResolveFile,其中表示将"~“放到相对文件中。所以我把我的appsettings.json改成
"plugin": {
"jobInitializer": {
"type": "Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz.Plugins",
"fileNames": "~\\quartz_jobs.xml"
}现在,windows服务能够读取quartz_jobs.xml。我期待着如果你改变了
properties["quartz.plugin.jobInitializer.fileNames"] = "quartz_jobs.xml";至
properties["quartz.plugin.jobInitializer.fileNames"] = "~\\quartz_jobs.xml";它也应该可以工作。
https://stackoverflow.com/questions/30712298
复制相似问题