有没有什么办法可以做一些“什么”呢;加总;c#中的CancelationTokenSource?
有没有办法实现CancelationTokenSource,它允许在内部聚合两个或多个其他CancelationToken?这让我可以这样写:有没有什么办法可以做一些“什么”呢;加总;c#中的CancelationTokenSource?,c#,C#,有没有办法实现CancelationTokenSource,它允许在内部聚合两个或多个其他CancelationToken?这让我可以这样写: void async Task DoSomeWorkAsync(CancelationToken Token) { var cts = AggregatedCancelationTokenSource(Token, new CancelationTokenSource(TimeSpan.FromSeconds(30)).Token)
void async Task DoSomeWorkAsync(CancelationToken Token)
{
var cts = AggregatedCancelationTokenSource(Token,
new CancelationTokenSource(TimeSpan.FromSeconds(30)).Token);
//Cancelation occurred:
// when timeout will be expired
// or
// when external Token.IsCancellationRequested will start to return "true"
await DoSomeOtherWorkAsync(cts.Token);
}
是的,您可以使用
CancellationTokenSource.CreateLinkedTokenSource
,来自:
创建将处于取消状态的CancellationTokenSource
当任何源令牌处于取消状态时
谢谢你的回答,我在谷歌搜索答案时错过了这篇文章)