JacekRobak85 JacekRobak85 - 2 months ago 36x
C# Question

How to parse cron expression in quartz

I have one problem which refers to quartz.net cron expressions. 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?
For example I have a cron:

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

I have tried use GetFinalFireTime() GetTimeAfter() GetNextValidTimeAfter() but application still throws exception:

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 vary thankfull if You tell me is there any cron parser library which allows to create crons easy. Something similar to cronMaker.com but proper working with quartz.net.
Many thanks in advance for Your help.



GetFinalFireTime hasn't been implemented yet.
GetNextValidTimeAfter should be working if you're using one of the latest versions.

If you want to generate cron expressions in c# you can use CronScheduleBuilder.


You can find a simple project here (QuartzNetCronExpressions.zip) where you can see how it works.

NOTE: I've used VS 2013, Framework 4.5.1 and Quartz.net 2.2.1 (nuget package).