I'm doing some OAuth work, where I get my refresh token through an provided async API method (GetRefreshTokenAsync):
public async Task<Tokens> RenewAuthentication()
{
AppTokenResult token = await OAuth.GetRefreshTokenAsync("clientid",
"clientsecret",
@"myRefreshToken");
string accessToken = token.AccessToken;
string refreshToken = token.RefreshToken;
return new Tokens(accessToken, refreshToken);
}
If I call this like from a non-async method as such:
public void noAsync()
{
var r = RenewAuthentication();
var x = r.Result;
}
It deadlocks the app :(. If I remove the 2nd line (r.Result), then it works, but that's crap, because I can't get the result. I tried reading
http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
But after trying his method 1 by adding .ConfigureAwait(false) to the GetRefreshTokenAsync() method it didn't make any difference.
Any advice?
RenewAuthentication, and then awaitrenewTask.ConfigureAwait(false). That said, I don't think you need the task anyway - just keep the awaitable around, and userenewAwaitable.GetResult(). If you're not hooking continuations, there's no need to keep the task. The awaitable has a better way to synchronously get the result :) - Luaan