visual-studio - 在立即窗口Visual Studio中调用异步方法

标签 visual-studio async-await immediate-window

我停在了一个断点上,我需要观察在这种情况下使用立即窗口调用异步函数的结果。所以我试过了

var things = await Client.GetThingsAsync("aParameter");

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'.



但是断点已经在异步方法中了。我也试着跑
var things = Client.GetThingsAsync("aParameter");

"Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation."



所以我尝试了 Watch 窗口
ClientGetThingsAsync("aParameter").Result;

"The function evaluation requires all threads to run."



编辑代码和重新构建让我很崩溃,因为每次构建需要 15 分钟。调试时可以使用哪些策略来调用异步调用?

最佳答案

你需要手动做事——没有 await

var things = ClientGetThingsAsync("aParameter").Result;

正如编译器所指出的,您需要一个 async 函数来使用 await ,但在使用即时窗口时您无法控制该函数。

关于visual-studio - 在立即窗口Visual Studio中调用异步方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59053129/

相关文章:

visual-studio - 如何从 Visual Studio 中的解决方案运行特定项目的干净构建

c# - 异步任务等待另一个任务

javascript - 何时使用 ES2017 内置的 'async' 或导入 'npm i async'

node.js - Sequelize 不返回 queryAsync 对象

c# - 如何确定变量的类型? (不是对象的类型)

javascript - 是否可以在 Web 应用程序中使用不同的 javascript 文件进行调试和生产?

c# - 为什么 Visual Studio 2012 生成的 Web 服务代理类以小写字母开头?

visual-studio - 如何在 Visual Studio 2015 中创建的 VSIX 中调试 Visual Studio 包

visual-studio - 立即窗口中的换行符

excel - 如何在立即窗口中打印范围变量? Excel VBA