是否有可能放弃像终止线程(Thread.Abort的方法)任务? [英] Is it possible to abort a Task like aborting a Thread (Thread.Abort method)?

查看:168
本文介绍了是否有可能放弃像终止线程(Thread.Abort的方法)任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以中止一个线程是这样的:

 线程的线程=新主题(的someMethod);
。
。
。
Thread.Abort的();
 

不过,我可以放弃任务(在.NET 4.0中)以同样的方式不是取消机制。 我想立刻杀死任务。

解决方案
  1. 您不应该使用Thread.Abort的()
  2. 任务可以取消,但不会中止。

借助 Thread.Abort的()方法是(严格)日precated。

否则,你运行使系统处于一个不稳定/不确定状态的风险

两个线程和任务应该合作被停止的时候,。

如果你需要运行一个进程,并从外面杀了它,唯一安全的选择是在一个单独的AppDomain中运行它。

We could abort a thread like this:

Thread thread = new Thread(SomeMethod);
.
.
.
thread.Abort();

But can I abort a Task (in .Net 4.0) in the same way not by cancellation mechanism. I want to kill the Task immediately.

解决方案

  1. You shouldn't use Thread.Abort()
  2. Tasks can be Cancelled but not aborted.

The Thread.Abort() method is (severely) deprecated.

Both Threads and Tasks should cooperate when being stopped, otherwise you run the risk of leaving the system in a unstable/undefined state.

If you do need to run a Process and kill it from the outside, the only safe option is to run it in a separate AppDomain.

这篇关于是否有可能放弃像终止线程(Thread.Abort的方法)任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆