【发布时间】:2013-03-29 09:17:08
【问题描述】:
我正在研究TPL Dataflow。 Belwo 是来自官方文档Stephen Toub. Introduction to TPL Dataflow (TPLDataflow.docx) 的两段代码sn-p。但我并没有完全理解它们之间的区别。
顺便说一句,这 2 个代码 sn-ps 是文档中的示例,用于演示目的。它们并不完整。
-
按顺序和同步下载图像
var downloader = new ActionBlock<string>(url => { // Download returns byte[] byte [] imageData = Download(url); Process(imageData); }); downloader.Post("http://msdn.com/concurrency"); downloader.Post("http://blogs.msdn.com/pfxteam"); -
按顺序和异步下载图像
var downloader = new ActionBlock<string>(async url => { byte [] imageData = await DownloadAsync(url); Process(imageData); }); downloader.Post("http://msdn.com/concurrency "); downloader.Post("http://blogs.msdn.com/pfxteam");
【问题讨论】:
-
我当然知道。但我需要在这里做一些详细的解释。因为正如我尝试的那样,输出看起来没有什么不同。
-
这是来自 MSDN 论坛的相关答案。 social.msdn.microsoft.com/Forums/en-US/tpldataflow/thread/…
标签: .net task-parallel-library async-await c#-5.0 tpl-dataflow