【问题标题】:Is it possible to add Schedule Start Date Time and Schedule End Date Time using ConTrigger?是否可以使用 ConTrigger 添加计划开始日期时间和计划结束日期时间?
【发布时间】:2014-06-24 11:02:58
【问题描述】:

我正在尝试使用 ConTrigger 添加计划开始日期时间和计划结束日期时间,这在 Quartz.net 中是否可行?

【问题讨论】:

    标签: quartz.net quartz.net-2.0


    【解决方案1】:

    是的,CronTrigger 支持这一点。 CronTriggerImpl 有一个构造函数可以让你这样做:

    /// <summary>
    /// Create a <see cref="CronTriggerImpl" /> with fire time dictated by the
    /// <param name="cronExpression" /> resolved with respect to the specified
    /// <param name="timeZone" /> occurring from the <see cref="startTimeUtc" /> until
    /// the given <paran name="endTimeUtc" />.
    /// </summary>
    /// <param name="name">The name of the <see cref="ITrigger" /></param>
    /// <param name="group">The group of the <see cref="ITrigger" /></param>
    /// <param name="jobName">name of the <see cref="IJobDetail" /> executed on firetime</param>
    /// <param name="jobGroup">Group of the <see cref="IJobDetail" /> executed on firetime</param>
    /// <param name="startTimeUtc">A <see cref="DateTimeOffset" /> set to the earliest time for the  <see cref="ITrigger" /> to start firing.</param>
    /// <param name="endTime">A <see cref="DateTimeOffset" /> set to the time for the <see cref="ITrigger" /> to quit repeat firing.</param>
    public CronTriggerImpl(string name, string group, string jobName,
        string jobGroup, DateTimeOffset startTimeUtc, 
        DateTimeOffset? endTime,
        string cronExpression, 
        TimeZoneInfo timeZone) : base(name, group, jobName, jobGroup)
    {
        CronExpressionString = cronExpression;
    
        if (startTimeUtc == DateTimeOffset.MinValue)
        {
            startTimeUtc = SystemTime.UtcNow();
        }
        StartTimeUtc = startTimeUtc;
    
        if (endTime.HasValue)
        {
            EndTimeUtc = endTime;
        }
        if (timeZone == null)
        {
            timeZone = TimeZoneInfo.Local;
        }
        else
        {
            TimeZone = timeZone;
        }
    }
    

    【讨论】: