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


C# Scheduler.Start方法代码示例

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


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

示例1: Given_scheduler_with_daily_item

        public void Given_scheduler_with_daily_item()
        {
            var context = new TestSchedulerContext();

            _scheduler = new Scheduler(context);

            var runsoon = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

            var foo1 = JobFactory.Daily("Foo1", () => { Console.WriteLine("Foo1"); foo1_calls += 1; }, runsoon, description: "Description for Foo1");
            var foo2 = JobFactory.Daily("Foo2", () => Console.WriteLine("Foo2"), runsoon);

            _scheduler.Schedule(foo1);
            _scheduler.Schedule(foo2);

            _scheduler.Start();

            Wait.Until(() => foo1_calls > 0, 30);

            context.MoveToTommorrow();

            Wait.Until(() => foo1_calls > 1, 30);

            context.MoveForwardNDays(2);

            Wait.Until(() => foo1_calls > 2, 50);
        }
开发者ID:JustApplications,项目名称:inline_scheduler,代码行数:26,代码来源:When_schedule_some_daily_work.cs

示例2: ItShouldStartAndStopWithoutExceptions

 public void ItShouldStartAndStopWithoutExceptions()
 {
     var scheduler = new Scheduler(new FakeLoggerFactory());
     scheduler.Start();
     var stopped = scheduler.Stop().Wait(4000);
     Assert.True(stopped);
 }
开发者ID:loudej,项目名称:coral,代码行数:7,代码来源:SchedulerTests.cs

示例3: PostShouldThrowExceptionAfterStop

 public void PostShouldThrowExceptionAfterStop()
 {
     var scheduler = new Scheduler(new FakeLoggerFactory());
     scheduler.Start();
     scheduler.Stop();
     Assert.Throws<InvalidOperationException>(() => scheduler.Post("testing", () => { }));
 }
开发者ID:loudej,项目名称:coral,代码行数:7,代码来源:SchedulerTests.cs

示例4: Main

        static void Main(string[] args)
        {
            System.Console.WriteLine("Application started -  Esc to quit");

            var sessionFactory = NHibernateFactory.AssembleSessionFactory(DATABASE_FILE);
            ILog consoleLogger = new ConsoleLogger {VerbosityLevel = 2};
            ILog databaseLogger = new Logger(new LogEntryDatabaseRepository(sessionFactory)) {VerbosityLevel = 1};
            ILog log = new CompositeLogger(consoleLogger, databaseLogger);

            var iocContainer = new IocContainerForScheduler();
            iocContainer.BindToConstant(sessionFactory);
            var taskDirectory = new DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName;

            var taskScheduler = new Scheduler(iocContainer, taskDirectory, new FileUtilities(), new TimerWithTimestamp(0, 10000), new TimerWithTimestamp(0, 2000), log);
            taskScheduler.Start();

            try
            {
                while (System.Console.ReadKey().Key != ConsoleKey.Escape) { }
            }
            catch (Exception e)
            {
                log.WriteEntry(new LogEntry(e.Source, e.Message, DateTime.Now));
            }
        }
开发者ID:ArildF,项目名称:Smeedee,代码行数:25,代码来源:Program.cs

示例5: Ctor_TimeSpan_Success

		public void Ctor_TimeSpan_Success()
		{
			Scheduler<BlockingScheduledAction> scheduler = new Scheduler<BlockingScheduledAction>(TimeSpan.FromSeconds(0.1));
			BlockingScheduledAction action = new BlockingScheduledAction();
			scheduler.Tasks.Add(new ScheduledTask<BlockingScheduledAction>(Schedule.CreateOneTime(DateTimeOffset.Now.AddSeconds(1.0)), action, true, null, null));
			scheduler.Start();
			Assert.IsTrue(scheduler.IsEnabled);

			Stopwatch watch = Stopwatch.StartNew();
			action.Waiter.WaitOne();
			Assert.IsTrue(watch.ElapsedMilliseconds < 2000);
			scheduler.Dispose();
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.Scheduler,代码行数:13,代码来源:SchedulerTest.cs

示例6: MultipleIterations_Success

		public void MultipleIterations_Success()
		{
			Scheduler<BlockingScheduledAction> scheduler = new Scheduler<BlockingScheduledAction>(TimeSpan.FromSeconds(0.1));
			BlockingScheduledAction action1 = new BlockingScheduledAction(10);
			scheduler.Tasks.Add(new ScheduledTask<BlockingScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(100.0), Weekdays.All), action1, true, null, null));
			BlockingScheduledAction action2 = new BlockingScheduledAction(5);
			scheduler.Tasks.Add(new ScheduledTask<BlockingScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(200.0), Weekdays.All), action2, true, null, null));
			scheduler.Start();

			Stopwatch watch = Stopwatch.StartNew();
			ManualResetEvent.WaitAny(new WaitHandle[] { action1.Waiter, action2.Waiter });
			Assert.IsTrue(watch.ElapsedMilliseconds < 1200);
			scheduler.Dispose();
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.Scheduler,代码行数:14,代码来源:SchedulerTest.cs

示例7: Given_scheduler_with_some_work

        public void Given_scheduler_with_some_work()
        {
            var ctx = new TestSchedulerContext();
            _scheduler = new Scheduler(ctx);

            _scheduler.Schedule("Foo1", () => { _foo1WorkDone = true; }, TimeSpan.FromMinutes(10));
            _scheduler.Schedule("Foo2", () => { _foo2WorkDone = true; }, TimeSpan.FromMinutes(10));

            // Lest ensure that all workitems
            // are applicable for schedule
            ctx.MoveToTommorrow();

            _scheduler.Start();

            Wait.Until(() => _scheduler.GatherOveralStats().RunningJobs + _scheduler.GatherOveralStats().ScheduledJobs == 0);
        }
开发者ID:chaliy,项目名称:inline_scheduler,代码行数:16,代码来源:When_do_some_work_items.cs

示例8: RunBot

        private static void RunBot()
        {
            try
            {
                var scheduler = new Scheduler();

                var container = CreateCompositionContainer();
                // Add all the sprockets to the sprocket list
                var announcements = container.GetExportedValues<IAnnounce>();

                Console.WriteLine(String.Format("Connecting to {0}...", _serverUrl));
                Bot bot = new Bot(_serverUrl, _botName, _botPassword);

                foreach (var s in container.GetExportedValues<ISprocket>())
                    bot.AddSprocket(s);

                bot.PowerUp();
                JoinRooms(bot);
                var users = bot.GetUsers(bot.Rooms.First());
                var user = bot.GetUserInfo(bot.Rooms.First(), users.First().Name.ToString());

                scheduler.Start(announcements, bot);

                Console.Write("Press enter to quit...");
                Console.ReadLine();

                scheduler.Stop();
                bot.ShutDown();

                _appShouldExit = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: " + e.GetBaseException().Message);
            }
        }
开发者ID:Raion,项目名称:jibbr,代码行数:36,代码来源:Program.cs

示例9: OnStart

 protected override void OnStart(string[] args)
 {
     _scheduler = new Scheduler();
     _scheduler.Start();
 }
开发者ID:awhatley,项目名称:pendulum,代码行数:5,代码来源:SchedulerService.cs

示例10: Main

        /// <summary>
        /// Application entry point.
        /// </summary>
        /// <param name="args">The execution arguments.</param>
        /// <returns>The application's exit code.</returns>
        public static int Main(string[] args)
        {
            int all = 0, backup = 0, man = 0, schedules = 0, restore = 0;
            string target = null;

            var options = new OptionSet()
            {
                { "a|all", "execute all backup and restore targets in the configuration.", v => { ++all; } },
                { "b|backup", "execute backup targets.", v => { ++backup; } },
                { "r|restore", "execute restore targets.", v => { ++restore; } },
                { "s|schedules", "execute schedules.", v => { ++schedules; } },
                { "t|target=", "the name of the specific backup/restore/schedule to execute.", v => target = v },
                { "m|man", "show this message", v => { ++man; } }
            };

            try
            {
                options.Parse(args);
            }
            catch (OptionException ex)
            {
                ParseError(options, ex);
                return 1;
            }

            if (man > 0)
            {
                Help(options);
                return 0;
            }

            if (all > 0)
            {
                ExecuteBackup(String.Empty);
                ExecuteRestore(String.Empty);
            }
            else if (backup > 0)
            {
                if (!ExecuteBackup(target))
                {
                    return 1;
                }
            }
            else if (restore > 0)
            {
                if (!ExecuteRestore(target))
                {
                    return 1;
                }
            }
            else if (schedules > 0)
            {
                ScheduleConfigurationElementCollection schd = new ScheduleConfigurationElementCollection();

                if (!String.IsNullOrEmpty(target))
                {
                    var schedule = SThreeQLConfiguration.Section.Schedules[target];

                    if (schedule != null)
                    {
                        schd.Add(schedule);
                    }
                    else
                    {
                        WriteError("There is no schedule defined for \"{0}\".", target);
                        return 1;
                    }
                }
                else
                {
                    foreach (var schedule in SThreeQLConfiguration.Section.Schedules)
                    {
                        schd.Add(schedule);
                    }
                }

                Scheduler scheduler = new Scheduler(schd);
                scheduler.BackupComplete += new EventHandler<DatabaseTargetEventArgs>(BackupComplete);
                scheduler.BackupCompressComplete += new EventHandler<DatabaseTargetEventArgs>(BackupCompressComplete);
                scheduler.BackupCompressStart += new EventHandler<DatabaseTargetEventArgs>(BackupCompressStart);
                scheduler.BackupStart += new EventHandler<DatabaseTargetEventArgs>(BackupStart);
                scheduler.BackupTransferComplete += new EventHandler<DatabaseTargetEventArgs>(BackupTransferComplete);
                scheduler.BackupTransferProgress += new EventHandler<DatabaseTargetEventArgs>(BackupTransferProgress);
                scheduler.BackupTransferStart += new EventHandler<DatabaseTargetEventArgs>(BackupTransferStart);
                scheduler.RestoreComplete += new EventHandler<RestoreDatabaseTargetEventArgs>(RestoreComplete);
                scheduler.RestoreDecompressComplete += new EventHandler<RestoreDatabaseTargetEventArgs>(RestoreDecompressComplete);
                scheduler.RestoreDecompressStart += new EventHandler<RestoreDatabaseTargetEventArgs>(RestoreDecompressStart);
                scheduler.RestoreStart += new EventHandler<RestoreDatabaseTargetEventArgs>(RestoreStart);
                scheduler.RestoreTransferComplete += new EventHandler<RestoreDatabaseTargetEventArgs>(RestoreTransferComplete);
                scheduler.RestoreTransferProgress += new EventHandler<RestoreDatabaseTargetEventArgs>(RestoreTransferProgress);
                scheduler.RestoreTransferStart += new EventHandler<RestoreDatabaseTargetEventArgs>(RestoreTransferStart);
                scheduler.ScheduleComplete += new EventHandler<ScheduleEventArgs>(ScheduleComplete);
                scheduler.ScheduleError += new EventHandler<ScheduleEventArgs>(ScheduleError);
                scheduler.ScheduleStart += new EventHandler<ScheduleEventArgs>(ScheduleStart);
                scheduler.Start();
//.........这里部分代码省略.........
开发者ID:ChadBurggraf,项目名称:sthreeql,代码行数:101,代码来源:SThreeQLConsole.cs

示例11: TaskStarting_Canceled_Success

		public void TaskStarting_Canceled_Success()
		{
			bool TaskStartingExecuted = false;
			Scheduler<BlockingScheduledAction> scheduler = new Scheduler<BlockingScheduledAction>(TimeSpan.FromSeconds(0.1));
			scheduler.TaskStarting += (sender, e) =>
			{
				e.Cancel = true;
				TaskStartingExecuted = true;
			};
			BlockingScheduledAction action1 = new BlockingScheduledAction();
			ScheduledTask<BlockingScheduledAction> task = new ScheduledTask<BlockingScheduledAction>(Schedule.CreateOneTime(DateTimeOffset.Now), action1, true, null, null);
			scheduler.Tasks.Add(task);
			scheduler.Start();

			SpinWait.SpinUntil(() => { return TaskStartingExecuted; });
			scheduler.Stop();

			Assert.IsNull(task.LastEndTime);

			scheduler.Dispose();
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.Scheduler,代码行数:21,代码来源:SchedulerTest.cs

示例12: TaskStarting_TaskCompleted_Success

		public void TaskStarting_TaskCompleted_Success()
		{
			bool TaskStartingExecuted = false;
			bool TaskCompletedExecuted = false;
			Scheduler<BlockingScheduledAction> scheduler = new Scheduler<BlockingScheduledAction>(TimeSpan.FromSeconds(0.1));
			scheduler.TaskCompleted += (sender, e) =>
			{
				TaskCompletedExecuted = true;
			};
			scheduler.TaskStarting += (sender, e) =>
			{
				TaskStartingExecuted = true;
			};
			BlockingScheduledAction action1 = new BlockingScheduledAction();
			scheduler.Tasks.Add(new ScheduledTask<BlockingScheduledAction>(Schedule.CreateOneTime(DateTimeOffset.Now), action1, true, null, null));
			scheduler.Start();

			action1.Waiter.WaitOne();
			scheduler.Stop();

			Assert.IsTrue(TaskCompletedExecuted, nameof(TaskCompletedExecuted));
			Assert.IsTrue(TaskStartingExecuted, nameof(TaskStartingExecuted));

			scheduler.Dispose();
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.Scheduler,代码行数:25,代码来源:SchedulerTest.cs

示例13: Interval_Success

		public void Interval_Success()
		{
			Scheduler<BlockingScheduledAction> scheduler = new Scheduler<BlockingScheduledAction>(TimeSpan.FromSeconds(1000.0));
			BlockingScheduledAction action1 = new BlockingScheduledAction(5);
			scheduler.Tasks.Add(new ScheduledTask<BlockingScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(200.0), Weekdays.All), action1, true, null, null));
			scheduler.Start();

			Assert.AreEqual(1000.0, scheduler.Interval.TotalSeconds);
			scheduler.Interval = TimeSpan.FromSeconds(0.1);

			Stopwatch watch = Stopwatch.StartNew();
			action1.Waiter.WaitOne();
			Assert.IsTrue(watch.ElapsedMilliseconds < 1200);
			scheduler.Dispose();
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.Scheduler,代码行数:15,代码来源:SchedulerTest.cs

示例14: Stop_TimeoutExpired_Error

		public void Stop_TimeoutExpired_Error()
		{
			Scheduler<WaitingScheduledAction> scheduler = new Scheduler<WaitingScheduledAction>(TimeSpan.FromSeconds(0.1));
			WaitingScheduledAction action1 = new WaitingScheduledAction();
			scheduler.Tasks.Add(new ScheduledTask<WaitingScheduledAction>(Schedule.CreateOneTime(DateTimeOffset.Now), action1, true, null, null));
			scheduler.Start();

			action1.StartWaiter.WaitOne();
			CustomAssert.ThrowsException<CodedTimeoutException>(() =>
			{
				scheduler.Stop(TimeSpan.FromSeconds(0.5));
			});
			action1.Waiter.Set();
			scheduler.Dispose();
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.Scheduler,代码行数:15,代码来源:SchedulerTest.cs

示例15: Stop_TimeoutNegative_Error

		public void Stop_TimeoutNegative_Error()
		{
			Scheduler<CancellableScheduledAction> scheduler = new Scheduler<CancellableScheduledAction>(TimeSpan.FromSeconds(0.1));
			scheduler.Stop();
			scheduler.Start();

			CustomAssert.ThrowsException<CodedArgumentOutOfRangeException>(() =>
			{
				scheduler.Stop(TimeSpan.FromSeconds(-1.0));
			});
			scheduler.Dispose();
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.Scheduler,代码行数:12,代码来源:SchedulerTest.cs


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