栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

Quartz.Net系列(七):Trigger之SimpleScheduleBuilder详解

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Quartz.Net系列(七):Trigger之SimpleScheduleBuilder详解

所有方法图

SimpleScheduleBuilder方法

RepeatForever:指定触发器将无限期重复。

WithRepeatCount:指定重复次数

var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s.WithIntervalInSeconds(1).RepeatForever()).Build();

        var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s.WithIntervalInSeconds(1)
                                                                     .WithRepeatCount(10)).Build();

注:底层实现是repeatCount+1,也就是总共执行repeatCount+1次
复制代码

    /// 
    /// Specify a the number of time the trigger will repeat - total number of
    /// firings will be this number + 1.
    /// 
    /// 
    /// 
    /// the number of seconds at which the trigger should repeat.
    /// the updated SimpleScheduleBuilder
    /// 
    /// 
    public SimpleScheduleBuilder WithRepeatCount(int repeatCount)
    {
        this.repeatCount = repeatCount;
        return this;
    }

复制代码

WithInterval:以毫秒为单位指定重复间隔,由于是TimeSpan也可以指定时分秒

WithIntervalInHours:以小时为单位指定重复间隔

WithIntervalInMinutes:以分钟单位指定重复间隔

WithIntervalInSeconds:以秒为单位指定重复间隔
复制代码
http://www.sina.com.cn/mid/search.shtml?q=%E8%85%BE%E9%BE%99%E5%A8%B1%E4%B9%90%E5%AE%98%E7%BD%91_181-8361-5678
var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s .WithIntervalInSeconds(1)
.WithInterval(TimeSpan.FromDays(1))
.WithIntervalInMinutes(1)
.WithIntervalInHours(1)
.WithRepeatCount(5))
.Build();

复制代码

注:底层都是通过WithInterval实现的
复制代码

    /// 
    /// Specify a repeat interval in milliseconds.
    /// 
    /// 
    /// 
    /// the time span at which the trigger should repeat.
    /// the updated SimpleScheduleBuilder
    /// 
    /// 
    public SimpleScheduleBuilder WithInterval(TimeSpan timeSpan)
    {
        interval = timeSpan;
        return this;
    }

    /// 
    /// Specify a repeat interval in seconds.
    /// 
    /// 
    /// 
    /// the time span at which the trigger should repeat.
    /// the updated SimpleScheduleBuilder
    /// 
    /// 
    public SimpleScheduleBuilder WithIntervalInSeconds(int seconds)
    {
        return WithInterval(TimeSpan.FromSeconds(seconds));
    }

复制代码

静态方法:

RepeatMinutelyForever

RepeatMinutelyForTotalCount

RepeatSecondlyForever

RepeatSecondlyForTotalCount

RepeatHourlyForever

RepeatHourlyForTotalCount

var trigger = TriggerBuilder.Create().WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForTotalCount(2)).Build();

复制代码

///
/// Create a SimpleScheduleBuilder set to repeat forever with a 1 minute interval.
///
///
///
/// the new SimpleScheduleBuilder
public static SimpleScheduleBuilder RepeatMinutelyForever()
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromMinutes(1))
.RepeatForever();

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat forever with an interval
    /// of the given number of minutes.
    /// 
    /// 
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatMinutelyForever(int minutes)
    {
        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromMinutes(minutes))
            .RepeatForever();

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat forever with a 1 second interval.
    /// 
    /// 
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatSecondlyForever()
    {
        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromSeconds(1))
            .RepeatForever();

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat forever with an interval
    /// of the given number of seconds.
    /// 
    /// 
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatSecondlyForever(int seconds)
    {
        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromSeconds(seconds))
            .RepeatForever();

        return sb;
    }

http://www.sina.com.cn/mid/search.shtml?q=%E7%BC%85%E7%94%B8%E8%85%BE%E9%BE%99%E5%AE%98%E7%BD%91_181-8361-5678
///
/// Create a SimpleScheduleBuilder set to repeat forever with a 1 hour interval.
///
///
///
/// the new SimpleScheduleBuilder
public static SimpleScheduleBuilder RepeatHourlyForever()
{
SimpleScheduleBuilder sb = Create()
.WithInterval(TimeSpan.FromHours(1))
.RepeatForever();

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat forever with an interval
    /// of the given number of hours.
    /// 
    /// 
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatHourlyForever(int hours)
    {
        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromHours(hours))
            .RepeatForever();

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat the given number
    /// of times - 1  with a 1 minute interval.
    /// 
    /// 
    /// Note: Total count = 1 (at start time) + repeat count
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatMinutelyForTotalCount(int count)
    {
        if (count < 1)
        {
            throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
        }

        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromMinutes(1))
            .WithRepeatCount(count - 1);

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat the given number
    /// of times - 1  with an interval of the given number of minutes.
    /// 
    /// 
    /// Note: Total count = 1 (at start time) + repeat count
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatMinutelyForTotalCount(int count, int minutes)
    {
        if (count < 1)
        {
            throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
        }

        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromMinutes(minutes))
            .WithRepeatCount(count - 1);

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat the given number
    /// of times - 1  with a 1 second interval.
    /// 
    /// 
    /// Note: Total count = 1 (at start time) + repeat count
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatSecondlyForTotalCount(int count)
    {
        if (count < 1)
        {
            throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
        }

        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromSeconds(1))
            .WithRepeatCount(count - 1);

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat the given number
    /// of times - 1  with an interval of the given number of seconds.
    /// 
    /// 
    /// Note: Total count = 1 (at start time) + repeat count
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatSecondlyForTotalCount(int count, int seconds)
    {
        if (count < 1)
        {
            throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
        }

        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromSeconds(seconds))
            .WithRepeatCount(count - 1);

        return sb;
    }

    /// 
    /// Create a SimpleScheduleBuilder set to repeat the given number
    /// of times - 1  with a 1 hour interval.
    /// 
    /// 
    /// Note: Total count = 1 (at start time) + repeat count
    /// 
    /// the new SimpleScheduleBuilder
    public static SimpleScheduleBuilder RepeatHourlyForTotalCount(int count)
    {
        if (count < 1)
        {
            throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
        }

        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromHours(1))
            .WithRepeatCount(count - 1);

        return sb;
    }

http://www.sina.com.cn/mid/search.shtml?q=%E8%85%BE%E9%BE%99%E5%9B%BD%E9%99%85_181-8361-5678
///
/// Create a SimpleScheduleBuilder set to repeat the given number
/// of times - 1 with an interval of the given number of hours.
///
///
/// Note: Total count = 1 (at start time) + repeat count
///
/// the new SimpleScheduleBuilder
public static SimpleScheduleBuilder RepeatHourlyForTotalCount(int count, int hours)
{
if (count < 1)
{
throw new ArgumentException("Total count of firings must be at least one! Given count: " + count);
}

        SimpleScheduleBuilder sb = Create()
            .WithInterval(TimeSpan.FromHours(hours))
            .WithRepeatCount(count - 1);

        return sb;
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/909143.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号