private async void ExecuteDownloadSubtitleCommand(SubtitleFileInfo parameter) { // Extract the relevant info from the filename TVShowValue fileInfo = _filenameProcessor.GetTVShowInfo(parameter); if (fileInfo != null) { // Add subtitle download to queue Scheduler.AddItem($"Downloading {parameter.Filename}...", (item, cancellation) => { try { foreach (var pluginStatus in PluginStatusList) { // Cancel if needed cancellation.ThrowIfCancellationRequested(); if (pluginStatus.Status == PluginLoadStatus.Loaded) { if ((pluginStatus.Interface.ProviderCapabilities() & SearchCapabilities.TV) == SearchCapabilities.TV) { IList <DownloadedSubtitle> downloadedSubs = new List <DownloadedSubtitle>(); ConcurrentQueue <ProviderSignal> cQueue = new ConcurrentQueue <ProviderSignal>(); //downloadedSubs = pluginStatus.Interface.SearchSubtitlesForTVAsync(fileInfo.Series, fileInfo.Season.GetValueOrDefault(), fileInfo.EpisodeNbr.GetValueOrDefault(), new List<CultureInfo>() { parameter.CultureInfo }).Result; var downloadTask = pluginStatus.Interface.SearchSubtitlesForTVAsync(fileInfo.Series, fileInfo.Season.GetValueOrDefault(), fileInfo.EpisodeNbr.GetValueOrDefault(), new List <CultureInfo>() { parameter.CultureInfo }, cQueue); while (!cQueue.IsEmpty || downloadTask.Status == TaskStatus.WaitingForActivation || downloadTask.Status == TaskStatus.Running) { // Check for signals from provider task if (cQueue.TryDequeue(out ProviderSignal result) == true) { if (result.Type == ProviderSignal.SignalType.ChangePercentage) { item.ProgressPercentage = result.DoubleValue; } else if (result.Type == ProviderSignal.SignalType.ChangeDetails) { item.DetailsText = result.TextValue; } } cancellation.ThrowIfCancellationRequested(); System.Threading.Thread.Sleep(10); } // Cancel if needed //cancellation.ThrowIfCancellationRequested(); // Get the result and process downloadedSubs = downloadTask.Result; // TODO: Decide what to do if multiple subs are downloaded. For now, just pick this one. if (downloadedSubs.Count > 0) { using (FileStream fs = new FileStream(parameter.FullPath, FileMode.Create)) { downloadedSubs[0].Contents.CopyTo(fs); downloadedSubs[0].Contents.Close(); } parameter.Exists = true; parameter.Parent.RefreshColor(); item.DetailsText = $"Successfully downloaded subtitle to path ({parameter.FullPath})"; return(true); } }