private async Task <bool> RenewTokensAsync(CancellationToken cancellationToken) { if (await _lock.WaitAsync(Timeout, cancellationToken).ConfigureAwait(false)) { try { var response = await _tokenClient.RequestClientCredentialsAsync(_scope, cancellationToken : cancellationToken).ConfigureAwait(false); if (!response.IsError) { _accessToken = response.AccessToken; #pragma warning disable 4014 Task.Run(() => { foreach (EventHandler <TokenRenewedEventArgs> del in TokenRenewed.GetInvocationList()) { try { del(this, new TokenRenewedEventArgs(response.AccessToken, response.ExpiresIn)); } catch { } } }).ConfigureAwait(false); #pragma warning restore 4014 return(true); } } finally { _lock.Release(); } } return(false); }