WPF 踩坑笔记11 线程取消
var cts = new CancellationTokenSource(); cancellationTokenSources.Add(cts); var t = Task.Run(() => { if (!cts.IsCancellationRequested) { //do something } }, cts.Token); cts.Token.Register(() => { //线程终止触发 });
var cts = new CancellationTokenSource(); cancellationTokenSources.Add(cts); var t = Task.Run(() => { if (!cts.IsCancellationRequested) { //do something } }, cts.Token); cts.Token.Register(() => { //线程终止触发 });