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/

相关文章:

javascript - 异步递归函数

c# - VS 2017即时窗口显示 "Internal error in the C# compiler"

c# - 将外部配置复制到 Visual Studio 中的本地项目?

c# - 等待 0.1 秒直到隐藏图像

c - ncurses,直接控制台输入,如何在没有*.lib,*.dll,*.h文件的vs17中实现?

c++ - stdlib 中的 _countof 损坏 : why?

c# - 异步方法异常的不同行为

c# - CA1001 在异步方法上实现 IDisposable

visual-studio - 高级 Visual Studio 功夫测试 -- 在调试期间从即时窗口调用函数