我有一个涉及quartz.net cron 表达式的问题。我读了很多文章并尝试了很多代码但没有任何结果,所以我感到有点绝望,这就是为什么我决定问你。也许有人也有类似的问题。 有什么方法可以将 Quartz.Net 的 cron 表达式解析为 DateTime 格式吗? 例如我有一个 cron:
var cron = new Quartz.CronExpression("0 * 8-22 * * ?");
我尝试使用 GetFinalFireTime() GetTimeAfter() GetNextValidTimeAfter() 但应用程序仍然抛出异常:
An unhandled exception of type 'System.AccessViolationException' occurred. Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
这是我的代码:
CronExpression cron = new Quartz.CronExpression("0 * 8-22 * * ?");
DateTimeOffset? nextFire = cron.GetNextValidTimeAfter(dt);
如果您能告诉我是否有任何 cron 解析器库可以轻松创建 cron,我也将非常感激。与 cronMaker.com 类似,但可以与 Quartz.Net 配合使用。
最佳答案
GetFinalFireTime
尚未 implemented yet .
如果您使用的是最新版本之一,GetNextValidTimeAfter
应该可以正常工作。
如果您想在 C# 中生成cron 表达式,您可以使用CronScheduleBuilder
。
更新:
可以找到一个简单的项目here (QuartzNetCronExpressions.zip),您可以在其中查看它是如何工作的。
注意:我使用过 VS 2013、Framework 4.5.1 和 Quartz.net 2.2.1(nuget 包)。
关于c# - 解析 Quartz.Net 中的 cron 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20803005/