摘要:
The Task: Events, Asynchronous Calls, Async and AwaitAlmost any software application today will likely contain a long-running process. “Long-running” may be a relative term but in the Windows Runtime it is specifically anything that could take longer than 50ms to execute. That’s a fairly small windo 阅读全文
posted @ 2013-08-27 20:18
武胜-阿伟
阅读(435)
评论(0)
推荐(0)
摘要:
Using the Task Parallel Library (TPL) for EventsThe parallel tasks library was introduced with the .NET Framework 4.0 and is designed to simplify parallelism and concurrency. The API is very straightforward and usually involves passing in an Action to execute. Things get a little more interesting wh 阅读全文
posted @ 2013-08-27 20:11
武胜-阿伟
阅读(452)
评论(0)
推荐(0)
摘要:
CCR,并发与协调运行时(Concurrency and Coordination Runtime)。从名字里我们就可以知道,这个东东是用来简化并发程序设计的。为何要并发呢?因为我们有多个任务需要处理,如果能同时做就会充分利用硬 件而减少处理的时间。自然的,CCR也是以“任务”为核心进行设计的,CCR中的代码也可以分为如下几个功能:描述任务、生成任务、调度任务和执行任务。描述任务对于计算机来说一个任务就是一段需要执行的代码,于是CCR有一个对任务的最抽象描述:ITask接口任务被封装在ITask实例中,当CCR调度这个任务实例去执行之后,CCR会调用ITask.Execute方法来执行该任务。 阅读全文
posted @ 2013-08-27 20:08
武胜-阿伟
阅读(1025)
评论(0)
推荐(0)
摘要:
Concurrency and Coordination RuntimeJeffrey RichterCode download available at:ConcurrentAffairs2006_09.exe(154 KB) Contents The Dispatcher ClassThe DispatcherQueue ClassThe Port and Arbiter ClassesThe Arbiter ClassCode ExamplesCoordinating Several I/O OperationsConclusionMicrosoft recently announce. 阅读全文
posted @ 2013-08-27 20:06
武胜-阿伟
阅读(529)
评论(0)
推荐(0)
摘要:
导读:CCR可以轻松的承载STA组件或者与它互操作:组件应该创建一个只有一个线程的CCR Dispatcher实例,并且在Dispatcher的构造函数中指定线程套间策略。DispatcherQueue实例就可以在与需要和遗留代码交互 的地方使用这个dispatcher来激活处理函数(activating handlers)。这些处理函数就可以安全的访问COM或者WinForm对象,同时对其他的CCR组件隐藏它们的STA关系,以便其他CCR组件可以 简单的投递元素到常规的CCR ports而不需要关心port上的处理函数使用的是什么dispatcher。原文链接线程套间约束当与某些遗留的Win 阅读全文
posted @ 2013-08-27 20:03
武胜-阿伟
阅读(359)
评论(0)
推荐(0)
摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using Microsoft.Ccr.Core;namespace ccrTest{ class Program { static void Main(string[] args) { int maxiQueueDepth = 10; // step1: 创建一个Dispatcher对象 ... 阅读全文
posted @ 2013-08-27 19:45
武胜-阿伟
阅读(339)
评论(0)
推荐(0)
摘要:
不用任何与创建线程、资源互斥有关系的API写多线程程序 这次的例子,是一个很简单的控制台,她将面对瞬间提交的百万的数据,而面不改色(CPU、内存非常平稳),队列中始终只保存最新的数据,每次只处理cpu 个数据(我的机器是双核的,所以,在我这里,就是每个CPU一个线程,真正的并行运行哦....),OK不废话,进入正题: 呃,既然是实例,那么就直接看代码好了:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingMicrosoft.Ccr.Co 阅读全文
posted @ 2013-08-27 19:36
武胜-阿伟
阅读(680)
评论(0)
推荐(0)
摘要:
不是非此即彼的场景。如下混合使用CCR+TPL的代码说明问题:It's not an either/or scenario.You can intermix CCR and TPL code like this, here is a Parallel.For inside of a Receive delegate:usingSystem;usingSystem.Threading;usingSystem.Threading.Tasks;usingMicrosoft.Ccr.Core;namespaceDemo{ publicclassProgram { publicstaticvoi 阅读全文
posted @ 2013-08-27 19:23
武胜-阿伟
阅读(205)
评论(0)
推荐(0)
摘要:
namespace TPLTest{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //var list = testFillParallel(); //int i = list.Count(); Stop... 阅读全文
posted @ 2013-08-27 18:21
武胜-阿伟
阅读(473)
评论(0)
推荐(0)
浙公网安备 33010602011771号