且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#:CancellationToken 不会取消阻塞方法

更新时间:2023-01-23 18:20:55

正如我在我的博客中所述,"你一直在那里使用那个 CancellationToken.我不认为这意味着你认为它意味着什么."

As I state on my blog, "You keep using that CancellationToken there. I do not think it means what you think it means."

特别是,传递给 StartNewCancellationToken 只会取消委托的 starting.如果您希望委托本身支持取消,则委托本身必须遵守 CancellationToken.

In particular, the CancellationToken passed to StartNew will only cancel the starting of the delegate. If you want the delegate itself to support cancellation, then the delegate itself will have to observe the CancellationToken.