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


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关键字只能在async方法中使用

关于异步

最新更新