简体   繁体   English

在Quartz.Net中解析cron表达式

[英]Parse cron expression in Quartz.Net

I have one problem which refers to quartz.net cron expressions. 我有一个问题涉及到quartz.net cron表达式。 I have read many articles and tried many pieces of code but without any results, so I feel little bit hopeless and that's why I decided to ask You. 我读了很多文章,尝试了许多代码,但是没有任何结果,所以我感到有些绝望了,这就是为什么我决定问你。 Maybe somebody also had similar problem. 也许有人也有类似的问题。 Is any way to parse cron expression for Quartz.Net to DateTime format? 有什么办法可以将Quartz.Net的cron表达式解析为DateTime格式? For example I have a cron: 例如,我有一个cron:

var cron = new Quartz.CronExpression("0 * 8-22 * * ?");

I have tried use GetFinalFireTime() GetTimeAfter() GetNextValidTimeAfter() but application still throws exception: 我曾尝试使用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.

Here is my code: 这是我的代码:

CronExpression cron = new Quartz.CronExpression("0 * 8-22 * * ?");
DateTimeOffset? nextFire = cron.GetNextValidTimeAfter(dt);

I also will be very thankful if you can tell me if is there any cron parser library which allows to create crons easy. 如果您能告诉我是否有任何cron解析器库可以轻松创建crons,我也将非常感谢。 Something similar to cronMaker.com but proper working with Quartz.Net. 与cronMaker.com类似,但可与Quartz.Net正常使用。

GetFinalFireTime hasn't been implemented yet . GetFinalFireTime尚未实现
GetNextValidTimeAfter should be working if you're using one of the latest versions. 如果您使用的是最新版本之一,则GetNextValidTimeAfter应该可以正常工作。

If you want to generate cron expressions in c# you can use CronScheduleBuilder . 如果要在c#中生成cron表达式 ,则可以使用CronScheduleBuilder

UPDATE: 更新:

You can find a simple project here (QuartzNetCronExpressions.zip) where you can see how it works. 您可以在此处找到一个简单的项目(QuartzNetCronExpressions.zip),在其中可以查看其工作原理。

NOTE: I've used VS 2013, Framework 4.5.1 and Quartz.net 2.2.1 (nuget package). 注意:我使用了VS 2013,Framework 4.5.1和Quartz.net 2.2.1(nuget软件包)。

I was facing this same problem.Somehow my project configuration for build was set x86. 我也面临着同样的问题,以某种方式将我用于构建的项目配置设置为x86。 It was not giving me option to change it.I unloaded project and changed it in notepad.Build configuration was set as "AnyCPU" and things started working Problem Solved 它没有给我选择更改它的选项。我卸载了项目并在记事本中进行了更改。构建配置设置为“ AnyCPU”,事情开始正常解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM