/// <summary> /// Downloads specified video. /// </summary> /// <param name="video">The video to download.</param> /// <param name="upgradeAudio">If true, only the audio will be downloaded and it will be merged with the local video file.</param> /// <param name="callback">The method to call once download is completed.</param> public async Task DownloadVideoAsync(string url, string destination, string description, EventHandler <DownloadCompletedEventArgs> callback, DownloadAction action, DownloadOptions options, object data) { if (IsDownloadDuplicate(url)) { return; } Directory.CreateDirectory(Path.GetDirectoryName(destination)); // Add DownloadItem right away before doing any async work. string DestinationNoExt = Path.Combine(Path.GetDirectoryName(destination), Path.GetFileNameWithoutExtension(destination)); DownloadItem DownloadInfo = new DownloadItem(url, destination, DestinationNoExt, description, action, callback, options, data); Application.Current.Dispatcher.Invoke(() => { downloadsList.Insert(0, DownloadInfo); // Notify UI of new download to show window. DownloadAdded?.Invoke(this, new EventArgs()); }); if (downloadsList.Where(d => d.Status == DownloadStatus.Downloading || d.Status == DownloadStatus.Initializing).Count() < Options.SimultaneousDownloads) { await StartDownloadAsync(DownloadInfo).ConfigureAwait(false); } }