是否还会处理通过 获得Dispose()
的CancellationTokenSource
任何子CancellationTokenRegistration
对象Token.Register()
?还是我必须单独处理每个注册?
示例 1:
async Task GoAsync(CancellationToken ct1, CancellationToken ct2)
{
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(ct1, ct2))
{
cts.Token.Register(() => Debug.Print("cancelled"), false)
await Task.Delay(1000, cts.Token);
}
}
示例 2:
async Task GoAsync(CancellationToken ct1, CancellationToken ct2)
{
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(ct1, ct2))
{
using (cts.Token.Register(() => Debug.Print("cancelled"), false))
{
await Task.Delay(1000, cts.Token);
}
}
}