public static async Task <RefreshedData> UpdateAccessToken(AccessTokenUpdatingArg tokenUpdatingArg) { Console.WriteLine("Обновление access token"); string responseContent = await CustomGoogleApiAccessTokenUpdater.RenewAccessToken(tokenUpdatingArg); dynamic responseObj = JsonConvert.DeserializeObject(responseContent); int expiresIn = responseObj.expires_in; string accessToken = responseObj.access_token; RefreshedData result = new RefreshedData { AccessToken = accessToken, ExpiresInSec = expiresIn }; return(result); }
private async Task StartEndlessAccessTokenUpdatingAsync(AccessTokenUpdatingArg tokenUpdatingArg, int firstDelaySec = 2) { int delaySec = firstDelaySec; while (true) { await Task.Delay(1000 *delaySec); RefreshedData result = TokenManagerService.UpdateAccessToken(tokenUpdatingArg).Result; lock (lockObj) { accessToken = result.AccessToken; } delaySec = result.ExpiresInSec; } // ReSharper disable once FunctionNeverReturns }