【发布时间】:2018-01-24 17:14:48
【问题描述】:
在我的调度程序中,使用quartz.net v3 实现,我正在尝试测试取消令牌的行为:
....
IScheduler scheduler = await factory.GetScheduler();
....
var tokenSource = new CancellationTokenSource();
CancellationToken ct = tokenSource.Token;
// Start scheduler
await scheduler.Start(ct);
// some sleep
await Task.Delay(TimeSpan.FromSeconds(60));
// communicate cancellation
tokenSource.Cancel();
我有一个无限运行的测试作业,并在 Execute 方法中检查取消令牌:
public async Task Execute(IJobExecutionContext context)
{
while (true)
{
if (context.CancellationToken.IsCancellationRequested)
{
context.CancellationToken.ThrowIfCancellationRequested();
}
}
}
我希望当tokenSource.Cancel() 被解雇时,作业将进入if 并引发异常。但它不起作用。
【问题讨论】:
标签: c# .net quartz-scheduler scheduler quartz.net