Call an async method in the immediate window Visual Studio
Asked Answered
C

2

21

I'm stopped in a breaking point and I need to watch the result of calling, in this context, an async function using the Immediate Window. So I tried

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

But the breakpoint is already inside an async method. Also I've tried to run

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

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

So I tried the Watch window with

ClientGetThingsAsync("aParameter").Result;

"The function evaluation requires all threads to run."

Editing the code and rebuilding is breaking me as it takes to build 15 minutes each time. What strategies are available to call async calls while debugging?

Certifiable answered 26/11, 2019 at 14:27 Comment(0)
O
18

You'll need to do things manually – without await.

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

As the compiler notes, you need an async function in which to use await, but you don't control the function when using the immediate window.

Ophthalmologist answered 26/11, 2019 at 14:31 Comment(5)
"Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation."Certifiable
The watch windows (you can have up to four open: look in the Debug | Windows menu while debugging) allow you to watch arbitrary expressionsOphthalmologist
I use ClientGetThingsAsync("aParameter").Result; and I get "The function evaluation requires all threads to run."Certifiable
@Certifiable I have seen that, using F5 to run until the next breakpoint will sometimes help. Otherwise debug in your main application code (rather than in the debugger) even if throw away code.Ophthalmologist
I did this in VS 2019 (16.11.5) in a ASP.NET Core 3.1 project and it made VS completely freeze and lock-up for 5 minutes before I killed it - wow.Hadwin
D
13

In the watch window, click on the little icon on the right side of the message. enter image description here

Dacey answered 10/1, 2021 at 14:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.