本文整理汇总了C#中Schedule.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Schedule.Execute方法的具体用法?C# Schedule.Execute怎么用?C# Schedule.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Schedule
的用法示例。
在下文中一共展示了Schedule.Execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_Be_Able_To_Schedule_Multiple_Simple_Methods
public void Should_Be_Able_To_Schedule_Multiple_Simple_Methods()
{
// Arrange
var job1 = false;
var job2 = false;
// Act
var schedule = new Schedule(() => job1 = true).AndThen(() => job2 = true);
schedule.Execute();
while (JobManager.RunningSchedules.Any())
Thread.Sleep(1);
// Assert
Assert.IsTrue(job1);
Assert.IsTrue(job2);
}
示例2: Should_Execute_Jobs_In_Order
public void Should_Execute_Jobs_In_Order()
{
// Arrange
var job1 = DateTime.MinValue;
var job2 = DateTime.MinValue;
// Act
var schedule = new Schedule(() =>
{
job1 = DateTime.Now;
Thread.Sleep(1);
}).AndThen(() => job2 = DateTime.Now);
schedule.Execute();
while (JobManager.RunningSchedules.Any())
Thread.Sleep(1);
// Assert
Assert.IsTrue(job1.Ticks < job2.Ticks);
}
示例3: Should_Remove_LongRunning_Job_But_Keep_Running
public void Should_Remove_LongRunning_Job_But_Keep_Running()
{
// Act
var schedule = new Schedule(() => Thread.Sleep(100));
schedule.WithName("remove long running job").ToRunNow().AndEvery(2).Seconds();
schedule.Execute();
// Assert
Assert.IsTrue(JobManager.RunningSchedules.Any(s => s.Name == "remove long running job"));
// Act
JobManager.RemoveJob("remove long running job");
// Assert
Assert.IsNull(JobManager.GetSchedule("remove long running job"));
Assert.IsTrue(JobManager.RunningSchedules.Any(s => s.Name == "remove long running job"));
Thread.Sleep(2000);
Assert.IsFalse(JobManager.RunningSchedules.Any(s => s.Name == "remove long running job"));
}