public async Task InitLoopAsync(TimeSpan timeout) { if (Logging.IsEnabled) { Logging.Enter(this, timeout, nameof(InitLoopAsync)); } CancellationTokenSource oldTokenSource = _cancellationTokenSource; _cancellationTokenSource = new CancellationTokenSource(); CancellationToken newToken = _cancellationTokenSource.Token; oldTokenSource?.Cancel(); oldTokenSource?.Dispose(); DateTime refreshOn = await _amqpIotCbsLink .SendTokenAsync( _amqpIotCbsTokenProvider, _connectionString.AmqpEndpoint, _audience, _audience, s_accessRightsStringArray, timeout) .ConfigureAwait(false); if (refreshOn < DateTime.MaxValue) { StartLoop(refreshOn, newToken); } if (Logging.IsEnabled) { Logging.Exit(this, timeout, nameof(InitLoopAsync)); } }
public async Task InitLoopAsync(CancellationToken cancellationToken) { if (Logging.IsEnabled) { Logging.Enter(this, nameof(InitLoopAsync)); } DateTime refreshOn = await _amqpIotCbsLink .SendTokenAsync( _amqpIotCbsTokenProvider, _connectionString.AmqpEndpoint, _audience, _audience, s_accessRightsStringArray, cancellationToken) .ConfigureAwait(false); if (refreshOn < DateTime.MaxValue) { StartLoop(refreshOn, cancellationToken); } if (Logging.IsEnabled) { Logging.Exit(this, nameof(InitLoopAsync)); } }