Click here to Skip to main content
15,888,277 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Learning TPL library here. If I wanted to break up ConfigureAwait so I get the returned value by an async method how should I do it?
ie. Given an async method GetDto() that returns an object of type Dto, normally called as:

var dto = await GetDto().ConfigureAwait(false);


In trying to understand how this breaks down, how would I do this
Task t = GetDto();
await t.ConfigureAwait(false);
//how do I capture the returned dto object here?
//also, 


Also, is it correct that in .Net Core 3 no need to call ConfigureAwait anymore? I thought that somehow the nature of the problem is that ConfigureAwait will always serve a purpose as you would want to be able to execute the continuation block in the same thread as the async call in situations that permits such ascontinuation code blocks that have no reference to UI objects?

Thanks

What I have tried:

Task t = GetDto();
Dto dto = await t.ConfigureAwait(false); //<-- doesn't work
Posted
Updated 5-Aug-20 0:35am

1 solution

Your GetDto method presumably returns a Task<Dto>:
C#
private async Task<Dto> GetDto() { ... }
In which case, your variable needs to be of the correct type:
C#
Task<Dto> t = GetDto();
Dto dto = await t.ConfigureAwait(false);
Or:
C#
ConfiguredTaskAwaitable<Dto> t = GetDto().ConfigureAwait(false);
Dto dto = await t;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900