处理异常

croire 3 years ago
parent 3f8a1f7fd3
commit 9a932b8759

@ -1,6 +1,7 @@
using DownKyi.Core.BiliApi.Login; using DownKyi.Core.BiliApi.Login;
using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.Downloader; using DownKyi.Core.Downloader;
using DownKyi.Core.Logging;
using DownKyi.Core.Settings; using DownKyi.Core.Settings;
using DownKyi.Core.Utils; using DownKyi.Core.Utils;
using DownKyi.Models; using DownKyi.Models;
@ -278,6 +279,8 @@ namespace DownKyi.Services.Download
// 下载进度回调 // 下载进度回调
mtd.TotalProgressChanged += (sender, e) => mtd.TotalProgressChanged += (sender, e) =>
{
try
{ {
// 状态更新 // 状态更新
var downloader = sender as MultiThreadDownloader; var downloader = sender as MultiThreadDownloader;
@ -306,6 +309,17 @@ namespace DownKyi.Services.Download
{ {
downloading.Downloading.MaxSpeed = speed; downloading.Downloading.MaxSpeed = speed;
} }
}
catch (InvalidOperationException ex)
{
Core.Utils.Debugging.Console.PrintLine($"{Tag}.DownloadByBuiltin()发生InvalidOperationException异常: {0}", ex);
LogManager.Error($"{Tag}.DownloadByBuiltin()", ex);
}
catch (Exception ex)
{
Core.Utils.Debugging.Console.PrintLine($"{Tag}.DownloadByBuiltin()发生异常: {0}", ex);
LogManager.Error($"{Tag}.DownloadByBuiltin()", ex);
}
}; };
// 文件合并完成回调 // 文件合并完成回调

@ -153,8 +153,8 @@ namespace DownKyi.Services.Download
} }
catch (Exception e) catch (Exception e)
{ {
Core.Utils.Debugging.Console.PrintLine(e); Core.Utils.Debugging.Console.PrintLine($"{Tag}.DownloadCover()发生异常: {0}", e);
LogManager.Error(Tag, e); LogManager.Error($"{Tag}.DownloadCover()", e);
} }
return null; return null;
@ -378,20 +378,20 @@ namespace DownKyi.Services.Download
} }
catch (InvalidOperationException e) catch (InvalidOperationException e)
{ {
Core.Utils.Debugging.Console.PrintLine("Start DoWork()发生InvalidOperationException异常: {0}", e); Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork()发生InvalidOperationException异常: {0}", e);
LogManager.Error("Start DoWork() InvalidOperationException", e); LogManager.Error($"{Tag}.DoWork() InvalidOperationException", e);
} }
catch (Exception e) catch (Exception e)
{ {
Core.Utils.Debugging.Console.PrintLine("Start DoWork()发生异常: {0}", e); Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork()发生异常: {0}", e);
LogManager.Error("Start DoWork()", e); LogManager.Error($"{Tag}.DoWork()", e);
} }
// 判断是否该结束线程若为true跳出while循环 // 判断是否该结束线程若为true跳出while循环
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
Core.Utils.Debugging.Console.PrintLine("AriaDownloadService: 下载服务结束跳出while循环"); Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork() 下载服务结束跳出while循环");
LogManager.Debug(Tag, "下载服务结束"); LogManager.Debug($"{Tag}.DoWork()", "下载服务结束");
break; break;
} }
@ -409,8 +409,8 @@ namespace DownKyi.Services.Download
await Task.WhenAny(Task.WhenAll(downloadingTasks), Task.Delay(30000)); await Task.WhenAny(Task.WhenAll(downloadingTasks), Task.Delay(30000));
foreach (Task tsk in downloadingTasks.FindAll((m) => !m.IsCompleted)) foreach (Task tsk in downloadingTasks.FindAll((m) => !m.IsCompleted))
{ {
Core.Utils.Debugging.Console.PrintLine("AriaDownloadService: 任务结束超时"); Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork() 任务结束超时");
LogManager.Debug(Tag, "任务结束超时"); LogManager.Debug($"{Tag}.DoWork()", "任务结束超时");
} }
} }

Loading…
Cancel
Save