TaskCompletionSource に関する私の質問の結果として
トークンを取得するために同様の手法を試しました
private t.Task<OAuthTokens> GetOAuthTokens()
{
var tcs = new t.TaskCompletionSource<OAuthTokens>();
t.Task.Run(
async () =>
{
var oauthService = new OAuthService(_configurationCloud);
var code = OAuthLogin.GetAuthorizationCode(_configurationCloud);
var response = await oauthService.GetTokensAsync(code);
tcs.SetResult(response);
});
return tcs.Task;
}
を使用してこれを呼び出す
var task1 = GetOAuthTokens();
_oAuthKeyService.OAuthResponse = task1.Result;
ただし、実行するとプログラムがロックされます。
以下は正常に動作します
var oauthService = new OAuthService(_configurationCloud);
var code = OAuthLogin.GetAuthorizationCode(_configurationCloud); // causes a login dialog
var tokens = oauthService.GetTokens(code);
_oAuthKeyService.OAuthResponse = tokens;
承認ダイアログ ボックスが表示されます。