I came across the following code that uses the ContinueWith() to wait for the result.
public async Task<User> GetUser()
{
return await _serviceRepo.GetUserAsync()
.ContinueWith(task =>
{
return task.Result;
});
}
Does the ContinueWith()
block the calling thread until task returns from the GetUserAsync()
call?
Since the task.Result
is inside the ContinueWith() which is scheduled, is anything being blocked while waiting for the antecedent task
?
I've seen this type of code in couple of other places, is this considered a best practice for the async/await pattern? I would expect the GetUserAsync()
call return the result than using a ContinueWith()
to wait for it.