How to:Aborting a long running task in TPL
http://social.msdn.microsoft.com/Forums/vstudio/en-US/d0bcb415-fb1e-42e4-90f8-c43a088537fb/aborting-a-long-running-task-in-tpl?forum=parallelextensions
I hesitate to show this :), but if you really did want to use aborts, you could do something like:
int Foo(CancellationToken token)
{
Thread t = Thread.CurrentThread;
using (token.Register(t.Abort))
{
// compute-bound work here
}
}
Then, if the token receives a cancellation request, it'll translate that into an abort on the thread running the compute-bound work. Of course, it'd be better if the "crunchy" operation were written to monitor the token, checking its IsCancellationRequest property or calling ThrowIfCancellationRequested every once in a while. This is what methods like Parallel.For and PLINQ do, and it provides for a nice cooperative cancellation mechanism whereby the caller can still be terminated in a timely fashion, but it can do so at a particular point when it's safe.
I hope that helps.
How to:Aborting a long running task in TPL的更多相关文章
- get running task , process and service
public class MyActivityManager extends ExpandableListActivity { private static final String NAME = & ...
- asp.net web api long running task
http://stackoverflow.com/questions/17577016/long-running-task-in-webapi http://blog.stephencleary.co ...
- TaskTracker任务初始化及启动task源码级分析
在监听器初始化Job.JobTracker相应TaskTracker心跳.调度器分配task源码级分析中我们分析的Tasktracker发送心跳的机制,这一节我们分析TaskTracker接受JobT ...
- C#并行编程-Task
菜鸟学习并行编程,参考<C#并行编程高级教程.PDF>,如有错误,欢迎指正. 目录 C#并行编程-相关概念 C#并行编程-Parallel C#并行编程-Task C#并行编程-并发集合 ...
- 【转】【C#】【Thread】【Task】多线程
多线程 多线程在4.0中被简化了很多,仅仅只需要用到System.Threading.Tasks.::.Task类,下面就来详细介绍下Task类的使用. 一.简单使用 开启一个线程,执行循环方法,返回 ...
- 【Hadoop代码笔记】Hadoop作业提交之TaskTracker获取Task
一.概要描述 在上上一篇博文和上一篇博文中分别描述了jobTracker和其服务(功能)模块初始化完成后,接收JobClient提交的作业,并进行初始化.本文着重描述,JobTracker如何选择作业 ...
- Hadoop作业提交之TaskTracker获取Task
[Hadoop代码笔记]Hadoop作业提交之TaskTracker获取Task 一.概要描述 在上上一篇博文和上一篇博文中分别描述了jobTracker和其服务(功能)模块初始化完成后,接收JobC ...
- Task Cancellation: Parallel Programming
http://beyondrelational.com/modules/2/blogs/79/posts/11524/task-cancellation-parallel-programming-ii ...
- Linux Hung Task分析
关键词:khungtaskd.TASK_UNINTERRUPTIBLE.nvcsw.nivcsw.last_switch_count等等. 经常会遇到内核打印“INFO: task xxx:xxx b ...
随机推荐
- Program Size: data=9.0 xdata=0 code=47
data=47.0 编译器编译后,程序总共需要占用47字节的片内RAM空间.注意这个大小仅仅是累加而已,并未考虑各个块之间的空隙,也就是说实际占用的RAM空间可能多于此数值.xdata=0 程序未使用 ...
- ELK-Stack 最后一次全篇文档
简介: ELK-Stack 日志收集系统.最后一次全篇记录的笔记,之后关于 ELK 的笔记都将是片段型.针对性的. 环境介绍: ELK-Stack:192.168.1.25 ( Redis.LogS ...
- JDBC中,如何动态的设置查询条件
今天看JDBC,发现有段代码,可以减少重复的编写查询方法,如下: public List<Goddess> query(List<Map<String, Object>& ...
- (转)C#命名规范
C#命名规范 数据类型 数据类型简写 标准命名举例 Array arr arrShoppingList Boolean bln blnIsPostB ...
- Lenovo SplitScreen联想分屏软件只能在联想电脑运行,如何破解
1.正常安装软件,重启电脑. 2.打开安装目录 C:\Program Files\Lenovo\Lenovo SplitScreen\SplitScreen 找到 MachineChecker.dll ...
- kubenetes dns
E0228 07:32:28.912833 1 reflector.go:201] k8s.io/dns/pkg/dns/dns.go:147: Failed to list *v1.En ...
- 01 lucene基础 北风网项目培训 Lucene实践课程 系统架构
Lucene在搜索的时候数据源可以是文件系统,数据库,web等等. Lucene的搜索是基于索引,Lucene是基于前面建立的索引之上进行搜索的. 使用Lucene就像使用普通的数据库一样. Luce ...
- 【BZOJ3238】差异【后缀自动机+dp】
题意 分析 这个题目还是很优秀的.sigma(len(Ti)+len(Tj))的值是一定的=n*(n+1)*(n-1)/2.那么关键就是求任意两个后缀的lcp的和了. 我们怎么求两个后缀的lcp?如果 ...
- pkg-config的妙用
1.每个lib下都会有个pkg-config文件夹,里面有相应pc文件 修改里面内容可以改变pkg-config显示 2.将.pc文件所在路径添加到PKG_CONFIG_PATH中如: export ...
- xgboost 里边的gain freq, cover
assuming that you're using xgboost to fit boosted trees for binary classification. The importance ma ...