并行执行解析任务

pull/745/head
Jeb Feng 2 years ago
parent eaa962aca1
commit a3436f98ea
No known key found for this signature in database
GPG Key ID: 5665CB572AB6EAF6

@ -19,6 +19,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
namespace DownKyi.Services.Download namespace DownKyi.Services.Download
{ {
@ -132,21 +133,24 @@ namespace DownKyi.Services.Download
} }
/// <summary> /// <summary>
/// 解析视频流 /// 并行解析视频流
/// </summary> /// </summary>
/// <param name="videoInfoService"></param> /// <param name="videoInfoService"></param>
public void ParseVideo(IInfoService videoInfoService) public void ParseVideo(IInfoService videoInfoService)
{ {
if (videoSections == null) { return; } if (videoSections == null) { return; }
List<Task> parsingTasks = new List<Task>();
foreach (VideoSection section in videoSections) foreach (VideoSection section in videoSections)
{ {
foreach (VideoPage page in section.VideoPages) foreach (VideoPage page in section.VideoPages)
{ {
// 执行解析任务 // 并行执行解析任务
videoInfoService.GetVideoStream(page); parsingTasks.Add(Task.Factory.StartNew(() => videoInfoService.GetVideoStream(page)));
} }
} }
Task.WaitAll();
} }
/// <summary> /// <summary>

@ -473,41 +473,20 @@ namespace DownKyi.ViewModels
{ {
case ParseScope.NONE: case ParseScope.NONE:
break; break;
// 以下三个case共享一套代码逻辑
case ParseScope.SELECTED_ITEM: 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: 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: case ParseScope.ALL:
var tasks = new List<Task>();
foreach (VideoSection section in VideoSections) foreach (VideoSection section in VideoSections)
{ {
foreach (VideoPage page in section.VideoPages) foreach (VideoPage page in section.VideoPages)
{ {
// 执行解析任务 // 并行执行解析任务
UnityUpdateView(ParseVideo, input, page); tasks.Add(Task.Factory.StartNew(() => UnityUpdateView(ParseVideo, input, page)));
} }
} }
Task.WaitAll(tasks.ToArray());
break; break;
default: default:
break; break;

Loading…
Cancel
Save