本文整理汇总了C#中Scheduler.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Scheduler.Dispose方法的具体用法?C# Scheduler.Dispose怎么用?C# Scheduler.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scheduler
的用法示例。
在下文中一共展示了Scheduler.Dispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dispose_Error
public void Dispose_Error()
{
Scheduler<WaitingScheduledAction>.CancellationTokenSchedulerAction action = new Scheduler<WaitingScheduledAction>.CancellationTokenSchedulerAction();
action.Dispose();
action.Dispose();
CustomAssert.ThrowsException<ObjectDisposedException>(() =>
{
action.ThrowIfCancellationRequested();
});
}
示例2: 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();
}
示例3: 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();
}
示例4: 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;
});
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例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();
}