简体   繁体   English

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

[英]How to resolve this error: await and cursor does not exist in current context

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);
            }
        }
    }
}

On executing it i am getting the following error: 在执行它时,我收到以下错误:

await and cursor does not exist in current context. 等待并且光标在当前上下文中不存在。

await keyword can be used inside async methods only await关键字只能在async方法中使用

about async 关于异步

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决“名称***在当前上下文中不存在”错误? - How to resolve “The name *** does not exist in the current context” error? 如何解决用于单元测试的错误“名称“ myClass”在当前上下文中不存在”? - How to resolve error, “The name 'myClass' does not exist in the current context” for unit test? 如何解决Stripe xamarin绑定错误? (CS0103名称“开始”在当前上下文中不存在) - How to resolve error on Stripe xamarin binding? (CS0103 The name 'Start' does not exist in the current context) async、await、context 和 next 在当前上下文中不存在 - async, await, context and next does not exist in the current context 当前上下文错误中不存在 - Does not exist in the current context error 错误:在当前上下文中不存在 - error: Does not exist in the current context 错误“当前上下文中不存在” - Error “Does not exist in current context” ASP.NET 内核 Web API - 如何解决错误 CS0103 名称“分数”在当前上下文中不存在 - ASP.NET Core Web API - How to resolve Error CS0103 The name 'score' does not exist in the current context 如何避免“当前上下文中不存在名称'ConfigurationManager'”错误? - How to avoid “The name 'ConfigurationManager' does not exist in the current context” error? 如何解决&#39;名称&#39;k&#39;在当前上下文中不存在&#39;的错误? - How to fix 'The name 'k' does not exist in the current context' error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM