并行执行解析任务

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

@ -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<Task>();
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;

Loading…
Cancel
Save