public static void AttemptDownload(object state) { try { Dictionary<SubtitleDownloader, List<SubtitleInfo>> subtitleDownloadInfo = new Dictionary<SubtitleDownloader, List<SubtitleInfo>>(); int totalSubtitlesFound = 0; string movieFilePath = state as string; if (!string.IsNullOrEmpty(movieFilePath)) { SetCurrentSubtitle(movieFilePath, string.Empty); lock (__filesInProgress) { __filesInProgress.Add(movieFilePath.ToLowerInvariant()); // This is for enforcing playlist refresh EventDispatch.DispatchEvent(LocalEvents.UpdatePlaylistNames, false); } Logger.LogTrace("A subtitle was not found for this movie. Attempting to download one ..."); try { string[] subtitleDownloadURIs = StringUtils.ToStringArray(ProTONEConfig.SubtitleDownloadURIs, '\\'); if (subtitleDownloadURIs != null) { int prio = 1; foreach (string subtitleDownloadURI in subtitleDownloadURIs) { SubtitleDownloader sd = null; List<SubtitleInfo> foundSubtitles = null; try { sd = SubtitleDownloader.FromDownloadURI(subtitleDownloadURI); if (sd.IsActive) { sd.Priority = prio++; foundSubtitles = sd.GetSubtitles(movieFilePath); } } catch (Exception ex) { Logger.LogException(ex); FireNotify(Translator.Translate("TXT_SUB_DOWNLOAD_ERROR"), Translator.Translate("TXT_ERROR"), MessageBoxIcon.Warning); } finally { if (sd != null) { if (foundSubtitles != null && foundSubtitles.Count > 0) { subtitleDownloadInfo.Add(sd, foundSubtitles); totalSubtitlesFound += foundSubtitles.Count; } } } } } if (totalSubtitlesFound < 1) { // No subtitles found, give message and exit FireNotify(Translator.Translate("TXT_NO_SUBS_FOUND"), Translator.Translate("TXT_CAUTION"), MessageBoxIcon.Warning); return; } else { MainThread.Post(delegate(object x) { SubtitleDownloadNotifyForm dlg = new SubtitleDownloadNotifyForm(movieFilePath, subtitleDownloadInfo); dlg.SubtitleDownloadNotify += new SubtitleDownloadNotifyHandler(dlg_SubtitleDownloadNotify); dlg.Show(); //dlg.CenterToScreen(); }); } // Perform cleanup foreach (SubtitleDownloader sd in subtitleDownloadInfo.Keys) { if (sd != null) { sd.Dispose(); } } } finally { lock (__filesInProgress) { __filesInProgress.Remove(movieFilePath.ToLowerInvariant()); // This is for enforcing playlist refresh EventDispatch.DispatchEvent(LocalEvents.UpdatePlaylistNames, false); } } } } finally { // This is for enforcing playlist refresh EventDispatch.DispatchEvent(LocalEvents.UpdatePlaylistNames, false); } }