Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call an async method in the immediate window Visual Studio

Tags:

People also ask

How do you call async method?

The simplest way to execute a method asynchronously is to start executing the method by calling the delegate's BeginInvoke method, do some work on the main thread, and then call the delegate's EndInvoke method. EndInvoke might block the calling thread because it does not return until the asynchronous call completes.

Can you call an async method without await?

In this way, an async function without an await expression will run synchronously. If there is an await expression inside the function body, however, the async function will always complete asynchronously. Code after each await expression can be thought of as existing in a .then callback.

Can we call async method in sync method?

Solution A If you have a simple asynchronous method that doesn't need to synchronize back to its context, then you can use Task. WaitAndUnwrapException : var task = MyAsyncMethod(); var result = task. WaitAndUnwrapException();

What happens when you call async method without await C#?

However, just to address "Call an async method in C# without await", you can execute the async method inside a Task. Run . This approach will wait until MyAsyncMethod finish. await asynchronously unwraps the Result of your task, whereas just using Result would block until the task had completed.


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?