Windows下的Crontab表达式解析DLL的使用

Linux的crontab工具特别的好用,正好现在工作总有好多定时执行的事

用Windows的定时任务觉得特别Low,哈哈,用C#写个任务触发器

然后再用上Crontab表达式解析DLL,觉得马上就高大上了

现在来讲下用法:

DLL文件下载地址

https://code.google.com/archive/p/ncrontab/

Demo调用示例

using System;
using NCrontab;
using System.Collections.Generic;


namespace crontabdemo
{
    class Program
    {
        public static void Main(string[] args)
        {
            DateTime begin = DateTime.Now;
            DateTime end = DateTime.Now.AddDays(1);
            string expression = "*/15 * * * *";
            IEnumerable<DateTime> list = CrontabSchedule.Parse(expression).GetNextOccurrences(begin,end);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach(DateTime dt in list)
            {
                sb.Append(dt.ToString("yyyy-MM-dd HH:mm:ss"));
                sb.Append(@"
");
                
            }
            Console.Write(sb.ToString());
            
            
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

 

enjoy :)

 

posted @ 2019-05-07 16:10  bigdog  阅读(408)  评论(0编辑  收藏  举报