From a3436f98eabfb572af624e682c53fe5767edf419 Mon Sep 17 00:00:00 2001 From: Jeb Feng Date: Sat, 13 May 2023 16:24:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B6=E8=A1=8C=E6=89=A7=E8=A1=8C=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Download/AddToDownloadService.cs | 10 ++++-- .../ViewModels/ViewVideoDetailViewModel.cs | 31 +++---------------- 2 files changed, 12 insertions(+), 29 deletions(-) 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;