【发布时间】:2015-12-03 09:21:07
【问题描述】:
documents 是一个IDictionary<string, string>,其中参数是<filename, fileUrl>
DocumentHandler.Download() 返回一个Task<Memorystram>
此代码有效:
foreach (var x in documents.Keys)
{
var result = await DocumentHandler.Download(new Uri(documents[x]));
// other code
}
但是它是同步运行的。
为了异步运行,我写了这段代码:
var keys =
documents.Keys.Select(async x =>
{
return Tuple.Create(x, await DocumentHandler.Download(new Uri(documents[x])));
});
await Task.WhenAll(keys);
foreach (var item in keys)
{
var tpl = item.Result;
// other code
}
它不起作用,它崩溃了,最后一行没有显示异常var tpl = item.Result;为什么?
【问题讨论】:
标签: c# exception asynchronous async-await