diff --git a/src/DownKyi/Services/Download/AddToDownloadService.cs b/src/DownKyi/Services/Download/AddToDownloadService.cs index 5edf7a9..0a7e7c0 100644 --- a/src/DownKyi/Services/Download/AddToDownloadService.cs +++ b/src/DownKyi/Services/Download/AddToDownloadService.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; +using System.Threading.Tasks; namespace DownKyi.Services.Download { @@ -132,21 +133,24 @@ namespace DownKyi.Services.Download } /// - /// 解析视频流 + /// 并行解析视频流 /// /// public void ParseVideo(IInfoService videoInfoService) { if (videoSections == null) { return; } + List parsingTasks = new List(); foreach (VideoSection section in videoSections) { foreach (VideoPage page in section.VideoPages) { - // 执行解析任务 - videoInfoService.GetVideoStream(page); + // 并行执行解析任务 + parsingTasks.Add(Task.Factory.StartNew(() => videoInfoService.GetVideoStream(page))); } } + + Task.WaitAll(); } /// diff --git a/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs b/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs index 7335cc3..ea6b518 100644 --- a/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs +++ b/src/DownKyi/ViewModels/ViewVideoDetailViewModel.cs @@ -473,41 +473,20 @@ namespace DownKyi.ViewModels { case ParseScope.NONE: break; + // 以下三个case共享一套代码逻辑 case ParseScope.SELECTED_ITEM: - foreach (VideoSection section in VideoSections) - { - foreach (VideoPage page in section.VideoPages) - { - if (page.IsSelected) - { - // 执行解析任务 - UnityUpdateView(ParseVideo, input, page); - } - } - } - break; case ParseScope.CURRENT_SECTION: - foreach (VideoSection section in VideoSections) - { - if (section.IsSelected) - { - foreach (VideoPage page in section.VideoPages) - { - // 执行解析任务 - UnityUpdateView(ParseVideo, input, page); - } - } - } - break; case ParseScope.ALL: + var tasks = new List(); foreach (VideoSection section in VideoSections) { foreach (VideoPage page in section.VideoPages) { - // 执行解析任务 - UnityUpdateView(ParseVideo, input, page); + // 并行执行解析任务 + tasks.Add(Task.Factory.StartNew(() => UnityUpdateView(ParseVideo, input, page))); } } + Task.WaitAll(tasks.ToArray()); break; default: break;