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 ...
随机推荐
- vue组件重新加载(刷新)
vue组件重新加载(刷新) 第一种方法:利用v-if控制router-view,在根组件APP.vue中实现一个刷新方法 <template> <router-view v-if=& ...
- Django xadmin的使用 (三)
关于报错: 1.在页面添加好新的用户后登录报错 解决方法: 新建一个app,名叫app D:\myfiles\study\python\django\datas>python manage.py ...
- Android apk couldn't install
an existing package with the same name and signature is already installed
- VS2017更新后 在WIN7上找不到 stdio.h等的问题
项目->属性->配置属性->常规->windows SDK版本.将其换成你现在的版本即可解决问题,如果不行就重新下个最新版SDK,如WIN10的.
- 双 MySQL 启动、停止脚本
5.5 启动 #!/bin/bash # author: Wang Xiaoqiang # func: Start MySQL 5.5 pid=`netstat -lnpt | awk -F '[ / ...
- 浅谈JobExecutionContext&JobDataMap
- java基础之HashSet如何保证对象的唯一性
首先Set集合是无序的 不可重复的 add的时候判断对象是否重复是用的equals HashSet<String> 存储String类型的数据时是可以保证数据的唯一性的 因为String类 ...
- 关于IOS新手在安装cocoa pods失败,因为ruby版本过低的解决方法+ (void) {升级ruby}
http://blog.csdn.net/zhaoen95/article/details/51995520 现在: 使用 OS 系统, 正在学习iOS 需要配置cocoapods 命令行中显 ...
- Lucas–Kanade光流算法学习
Lucas–Kanade光流算法是一种两帧差分的光流估计算法.它由Bruce D. Lucas 和 Takeo Kanade提出. 光流(Optical flow or optic f ...
- Cisco VPP启动流程
Cisco VPP启动流程,有需要的朋友可以参考一下. VPP初始化 VLIB_INIT_FUNCTION用来定义构造函数,注册函数到vlib_main_t->init_function_reg ...