小编jia*_*hen的帖子

是否有可能"等待收益率返回DoSomethingAsync()"

常规迭代器块(即"yield return")是否与"async"和"await"不兼容?

这样可以很好地了解我正在尝试做的事情:

async Task<IEnumerable<Foo>> Method(String [] Strs)
{
    // I want to compose the single result to the final result, so I use the SelectMany
    var finalResult = UrlStrings.SelectMany(link =>   //i have an Urlstring Collection 
                   await UrlString.DownLoadHtmlAsync()  //download single result; DownLoadHtmlAsync method will Download the url's html code 
              );
     return finalResult;
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到编译器错误,引用"无法从资源加载消息字符串".

这是另一种尝试:

async Task<IEnumerable<Foo>> Method(String [] Strs)
{
    foreach(var str in strs)
    {
        yield return await DoSomethingAsync( str)
    }
}
Run Code Online (Sandbox Code Playgroud)

但同样,编译器返回错误:"无法从资源加载消息字符串".


这是我项目中真正的编程代码

当我有一个List Task时,这非常有用,该任务可以从URL下载HTML,我使用语法"yield return await task",结果是我想要的 …

c# async-await c#-5.0 iasyncenumerable

98
推荐指数
6
解决办法
6万
查看次数

标签 统计

async-await ×1

c# ×1

c#-5.0 ×1

iasyncenumerable ×1