相关疑难解决方法(0)

如何从.NET 4.5中的并行任务中获益

我想使用.NET迭代器和并行Tasks/await?.像这样的东西:

IEnumerable<TDst> Foo<TSrc, TDest>(IEnumerable<TSrc> source)
{
    Parallel.ForEach(
        source,
        s=>
        {
            // Ordering is NOT important
            // items can be yielded as soon as they are done                
            yield return ExecuteOrDownloadSomething(s);
        }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是.NET无法原生地处理这个问题.到目前为止@svick的最佳答案 - 使用AsParallel().

奖励:任何实现多个发布者和单个订阅者的简单异步/等待代码?订阅者将屈服,并且pubs将处理.(仅核心库)

c# yield-return task-parallel-library async-await c#-5.0

9
推荐指数
1
解决办法
4336
查看次数