你不能
任务使用线程池中的后台线程。另外,也不建议使用Abort方法取消线程。您可以查看以下博客文章,该文章说明了使用取消令牌取消任务的正确方法。这是一个例子:
class Program{ static void Main() { var ts = new CancellationTokenSource(); CancellationToken ct = ts.Token; Task.Factory.StartNew(() => { while (true) { // do some heavy work here Thread.Sleep(100); if (ct.IsCancellationRequested) { // another thread decided to cancel Console.WriteLine("task canceled"); break; } } }, ct); // Simulate waiting 3s for the task to complete Thread.Sleep(3000); // Can't wait anymore => cancel this task ts.Cancel(); Console.ReadLine(); }}


