How to cancel parallel loops in .NET C# z
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); Task.Factory.StartNew(() =>
{
Thread.Sleep();
cancellationTokenSource.Cancel();
Console.WriteLine("Token cancelled");
}); ParallelOptions parallelLoopOptions =
new ParallelOptions()
{
CancellationToken = cancellationTokenSource.Token
}; try
{
Parallel.For(, Int64.MaxValue, parallelLoopOptions, index =>
{
double result = Math.Pow(index, );
Console.WriteLine("Index {0}, result {1}", index, result);
Thread.Sleep();
});
}
catch (OperationCanceledException)
{
Console.WriteLine("Cancellation exception caught!");
}
How to cancel parallel loops in .NET C# z的更多相关文章
- Parallel for loops in .NET C# z
The start index: this is inclusive, i.e. this will be the first index value in the loop The end inde ...
- Parallel for-each loops in .NET C# z
An IEnumerable object An Action of T which is used to process each item in the list List<string&g ...
- Parallel stepped for loops in .NET C# z
; i < ; i += ) public IEnumerable<int> SteppedIntegerList(int startIndex, int endEndex, int ...
- Breaking parallel loops in .NET C# using the Stop method z
List<, , , , , , , , , }; Parallel.ForEach(integers, (int item, ParallelLoopState state) => { ...
- Task Cancellation: Parallel Programming
http://beyondrelational.com/modules/2/blogs/79/posts/11524/task-cancellation-parallel-programming-ii ...
- C++11: Multi-core Programming – PPL Parallel Aggregation Explained
https://katyscode.wordpress.com/2013/08/17/c11-multi-core-programming-ppl-parallel-aggregation-expla ...
- .NET并行编程1 - 并行模式
设计模式——.net并行编程,清华大学出版的中译本. 相关资源地址主页面: http://parallelpatterns.codeplex.com/ 代码下载: http://parallelpat ...
- Optimize Managed Code For Multi-Core Machines
Parallel Performance Optimize Managed Code For Multi-Core Machines Daan Leijen and Judd Hall This ar ...
- 7.OpenACC
OpenACC: openacc 可以用于fortran, c 和 c++程序,可以运行在CPU或者GPU设备. openacc的代码就是在原有的C语言基础上进行修改,通过添加:compiler di ...
随机推荐
- EXTJS 4.2 资料 Grid嵌套
如图: var ParentContCateId = 0; var start = 0; var limit = 20; DistributionPointForm = function () { E ...
- owa Your request can't be completed right now. Please try again later.
Your request can't be completed right now. Please try again later.
- 文件/图片,批量上传【神器】--WebUploader
<system.web> <httpRuntime maxRequestLength="102400" executionTimeout="720&qu ...
- swift基础--变量
(1)变量与常量 (2)基本类型 (3)强制转换 (4)Bool类型 (5)元组 (6)可选值 //变量和常量 var str = "Hello, playground" let ...
- hdu 4101
比赛的时候先是受以前一个圣神海的题目 用了两遍DFS 第一遍标记出围墙 第二遍求围墙外和每块围墙降为1所需的攻击次数 结果爆栈 改为BFS后AC DFS的加了一句这个 #pragma comme ...
- 网络爬虫-url索引
网络爬虫-url索引 http://www.cnblogs.com/yuandong/archive/2008/08/28/Web_Spider_Url_Index.html url索引的作用是判断一 ...
- spring <form:checkboxes> tag and css class
I have issue with: <form:checkboxes path="roles" cssClass="checkbox" items=&q ...
- 【疯狂Java讲义学习笔记】【数据类型与运算符】
[学习笔记]1.8bit = 1byte,4byte = 1word.Java中的整型数据有byte(1字节),short(2字节),int(4字节),long(8字节).Java中的浮点数据有flo ...
- CentOS下安装XAMPP详细教程
现在php的集成运行环境越来越多,个人比较喜欢XAMPP,更新速度快,好用,安装便捷.windows下面的安装,就是下一步.下一步,没什么好说的,详细说一下linux下面的安装,这里以CentOS为例 ...
- matlab 在代码中,显示错误,退出程序
使用函数error('message_id', 'message'),出现错误时函数中止运行. 参考http://www.ilovematlab.cn/thread-43261-1-1.html