本文整理汇总了C#中Scheduler.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Scheduler.Stop方法的具体用法?C# Scheduler.Stop怎么用?C# Scheduler.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scheduler
的用法示例。
在下文中一共展示了Scheduler.Stop方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItShouldStartAndStopWithoutExceptions
public void ItShouldStartAndStopWithoutExceptions()
{
var scheduler = new Scheduler(new FakeLoggerFactory());
scheduler.Start();
var stopped = scheduler.Stop().Wait(4000);
Assert.True(stopped);
}
示例2: PostShouldThrowExceptionAfterStop
public void PostShouldThrowExceptionAfterStop()
{
var scheduler = new Scheduler(new FakeLoggerFactory());
scheduler.Start();
scheduler.Stop();
Assert.Throws<InvalidOperationException>(() => scheduler.Post("testing", () => { }));
}
示例3: CancelOperations_Success
public void CancelOperations_Success()
{
Scheduler<CancellableScheduledAction> scheduler = new Scheduler<CancellableScheduledAction>(TimeSpan.FromSeconds(0.1));
CancellableScheduledAction action1 = new CancellableScheduledAction();
scheduler.Tasks.Add(new ScheduledTask<CancellableScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(100.0), Weekdays.All), action1, true, null, null));
CancellableScheduledAction action2 = new CancellableScheduledAction();
scheduler.Tasks.Add(new ScheduledTask<CancellableScheduledAction>(Schedule.CreateInterval(DateTimeOffset.Now, TimeSpan.FromMilliseconds(200.0), Weekdays.All), action2, true, null, null));
scheduler.Start();
ManualResetEvent.WaitAny(new WaitHandle[] { action1.Waiter, action2.Waiter });
Stopwatch watch = Stopwatch.StartNew();
scheduler.Stop();
Assert.IsTrue(watch.ElapsedMilliseconds < 200);
scheduler.Dispose();
}
示例4: 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);
}
}
示例5: Disposed_Error
public void Disposed_Error()
{
Scheduler<BlockingScheduledAction> scheduler = new Scheduler<BlockingScheduledAction>();
scheduler.Tasks.Add(new ScheduledTask<BlockingScheduledAction>(Schedule.CreateOneTime(DateTimeOffset.Now), new BlockingScheduledAction(), true, null, null));
scheduler.Start();
scheduler.Start();
scheduler.Dispose();
scheduler.Dispose();
scheduler.Stop();
CustomAssert.ThrowsException<ObjectDisposedException>(() =>
{
int i = scheduler.Tasks.Count;
});
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}