private void StartConsumingResumeQueue() { _logger.Debug("Starting to consume resume queue."); while (_resumeQueue.Count != 0 && !_isStopped) { FileStreamInformation fileStreamInformation = _resumeQueue.Dequeue(); try { SendDownloadRequest(fileStreamInformation); _fileWriter.ResumeFileWrite(fileStreamInformation); } catch (StreamDisconnectedException ex) { _logger.Warn($"Received an StreamDisconnectedException while downloading file {fileStreamInformation.FullPath}. Trying to resume.", ex); if (fileStreamInformation.RetryCount-- > 0) { _resumeQueue.Enqueue(fileStreamInformation); } } catch (Exception ex) { if (File.Exists(fileStreamInformation.FullPath)) { File.Delete(fileStreamInformation.FullPath); } _logger.Error($"Failed to download file with url: {fileStreamInformation.FullPath}", ex); } } }