如何解决此错误:当前上下文中不存在await和cursor

时间:2015-09-17 04:27:05

标签: c# .net

private void button10_Click(object sender, EventArgs e)
{
    var db = mongo.GetDatabase("milk123");
    mongo.Connect();
    var collection = db.GetCollection<BsonDocument>("stock123");
    using (var cursor = await col.Find(new BsonDocument()).ToCursorAsync())
    {
        while (await cursor.MoveNextAsync())
        {
            foreach (var doc in cursor.Current)
            {
                Console.WriteLine(doc);
            }
        }
    }
}

执行它时,我收到以下错误:

await和cursor在当前上下文中不存在。

1 个答案:

答案 0 :(得分:1)

await关键字只能在async种方法中使用

about async