// This is async void on purpose because this is supposed to be always ran in background private async void EnqueueDownload(DownloadViewModel download) { // Cancel an existing download for this file path to prevent writing to the same file Downloads.FirstOrDefault(d => d.FilePath == download.FilePath)?.Cancel(); // Add to list Downloads.Add(download); // If download option is not set - get the best download option if (download.DownloadOption == null) { download.DownloadOption = await _downloadService.GetBestDownloadOptionAsync(download.Video.Id, download.Format); } // Download try { await _downloadService.DownloadVideoAsync(download.Video.Id, download.FilePath, download.DownloadOption, download.GetProgressRouter(), download.CancellationToken); } catch (OperationCanceledException) { // Ignore cancellations } // Mark download as completed download.MarkAsCompleted(); }