private async Task BackgroundCleanup(ICacheStack cacheStack) { var cancellationToken = TokenSource.Token; while (!cancellationToken.IsCancellationRequested) { await Task.Delay(Frequency, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); await cacheStack.CleanupAsync(); } }
private async Task BackgroundCleanup(ICacheStack cacheStack) { try { var cancellationToken = TokenSource.Token; while (!cancellationToken.IsCancellationRequested) { await Task.Delay(Frequency, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); await cacheStack.CleanupAsync(); } } catch (Exception ex) when(ex is TaskCanceledException || ex is OperationCanceledException) { } }