public async ValueTask TransmitFromStorage(long maxFilesToTransmit, bool async, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return; } long files = maxFilesToTransmit; while (files > 0) { try { // TODO: Do we need more lease time? var blob = _storage.GetBlob()?.Lease(10000); if (blob == null) { // no files to transmit return; } else { var data = blob.Read(); using var httpMessage = async ? await _applicationInsightsRestClient.InternalTrackAsync(data, cancellationToken).ConfigureAwait(false) : _applicationInsightsRestClient.InternalTrackAsync(data, cancellationToken).Result; var result = IsSuccess(httpMessage); if (result == ExportResult.Success) { blob.Delete(); AzureMonitorExporterEventSource.Log.WriteInformational("TransmitFromStorageSuccess", "Successfully transmitted a blob from storage."); } else { HandleFailures(httpMessage, blob); } } } catch (Exception ex) { AzureMonitorExporterEventSource.Log.WriteError("FailedToTransmitFromStorage", ex); } files--; } }