当前位置: 首页>>代码示例>>C#>>正文


C# Scheduler.RecurringRun方法代码示例

本文整理汇总了C#中Scheduler.RecurringRun方法的典型用法代码示例。如果您正苦于以下问题:C# Scheduler.RecurringRun方法的具体用法?C# Scheduler.RecurringRun怎么用?C# Scheduler.RecurringRun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scheduler的用法示例。


在下文中一共展示了Scheduler.RecurringRun方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        private static void Main(string[] args)
        {
            var scheduler = new Scheduler(TimeSpan.FromSeconds(1));

            Console.WriteLine("{0}: App is started", DateTime.Now);

            //// Run once in 5 secs from now
            //scheduler.SingleRun(
            //    DateTime.Now.AddSeconds(5),
            //    () => Console.WriteLine("{0}: Hello from SingleRun", DateTime.Now));

            //// run every 3 secs (first run in 3 secs from now)
            //scheduler.RecurringRun(
            //    interval: TimeSpan.FromSeconds(3),
            //    task: () => Console.WriteLine("{0}: This 'every 3 secs' task with no First Run value", DateTime.Now));

            //// run every 3 secs (first run is immediate)
            //scheduler.RecurringRun(
            //    interval: TimeSpan.FromSeconds(3),
            //    task: () => Console.WriteLine("{0}: This 'every 3 secs' task with immediate First Run", DateTime.Now),
            //    immediateFirstRun: true);

            // run daily, first run at (Now + 15sec)
            scheduler.RecurringRun(
                firstRun: DateTime.Today.AddHours(8),
                interval: TimeSpan.FromDays(1),
                task: () => Console.Write("Emails are sent every day at 8:00 am"));

            // run daily at (Now+8:00 AM
            var sendEmailTask = scheduler.RecurringRun(
                firstRun: DateTime.Today.AddHours(8),
                interval: TimeSpan.FromDays(1),
                task: () => Console.Write("Emails are sent every day at 8:00 am"));

            //// Immediate first Run with no First Run specified
            //var cancelationDemoTaskCnt = 0;
            //var cancelationDemoTask = scheduler.RecurringRun(
            //    interval: TimeSpan.FromMinutes(5),
            //    task: () =>
            //    {
            //        cancelationDemoTaskCnt++;
            //        Console.WriteLine("{0}: CancelationDemoTask, run #{1}", DateTime.Now, cancelationDemoTaskCnt);
            //    });

            //// Watch for some changes every 5 mins
            //scheduler.RecurringRun(
            //    TimeSpan.FromMinutes(5),
            //    () =>
            //    {
            //        // adjust schedule for SendEmailTask
            //        TimeSpan timeOfDay;
            //        TimeSpan interval;
            //        GetScheduleFromDB(out timeOfDay, out interval);

            //        sendEmailTask.AdjustSchedule(timeOfDay, interval);

            //        // limit amount of runs for demoTask
            //        if (cancelationDemoTaskCnt >= 5)
            //        {
            //            cancelationDemoTask.Discard();
            //        }
            //    });

            Console.ReadLine();
        }
开发者ID:davidich,项目名称:TaskScheduler,代码行数:65,代码来源:Program.cs


注:本文中的Scheduler.RecurringRun方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。