Create Cron Expression using Quartz .NET

吃可爱长大的小学妹 提交于 2019-12-07 09:06:01

问题


Is it possible using the Quartz .NET assembly to generate a cron expression? I saw that the CronScheduleBuilder class has a private member cronExpression which is essentially what I am looking for. Is there any other way to get the cron expression itself?


回答1:


Possible using ICronTrigger.CronExpressionString

CronScheduleBuilder csb = CronScheduleBuilder
    .WeeklyOnDayAndHourAndMinute(DayOfWeek.Monday, 12, 0);

ICronTrigger trigger = (ICronTrigger)TriggerBuilder
    .Create()
    .WithSchedule(csb)
    .Build();

string cronExpression = trigger.CronExpressionString;



回答2:


Using Ian answer, I have created a small extension method. Hopefully it will be useful for someone else...

public static class QuartzExtensionMethods
{
    public static string ToCronString(this CronScheduleBuilder cronSchedule)
    {
        ICronTrigger trigger = (ICronTrigger)TriggerBuilder
        .Create()
        .WithSchedule(cronSchedule)
        .Build();

        return trigger.CronExpressionString;
    }
}


来源:https://stackoverflow.com/questions/13567180/create-cron-expression-using-quartz-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!