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