【发布时间】:2016-02-07 00:55:27
【问题描述】:
当我尝试将 await 关键字与 FindAll(filter) 方法一起使用时,我最终得到了不可编译的代码。例如:
using (var cursor = await collection.FindAsync(filter))
{
while (await cursor.MoveNextAsync())
{
var batch = cursor.Current;
foreach (var document in batch)
{
// process document
count++;
}
}
}
正在给予:
The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
如果我查看源代码,该方法确实返回了Task:
public static Task<IAsyncCursor<TDocument>> FindAsync<TDocument>(...)
知道这里发生了什么吗?
【问题讨论】:
标签: c# mongodb visual-studio-2010 async-await