处理异常

croire 3 years ago
parent 3f8a1f7fd3
commit 9a932b8759

@ -1,6 +1,7 @@
using DownKyi.Core.BiliApi.Login;
using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.Downloader;
using DownKyi.Core.Logging;
using DownKyi.Core.Settings;
using DownKyi.Core.Utils;
using DownKyi.Models;
@ -279,32 +280,45 @@ namespace DownKyi.Services.Download
// 下载进度回调
mtd.TotalProgressChanged += (sender, e) =>
{
// 状态更新
var downloader = sender as MultiThreadDownloader;
try
{
// 状态更新
var downloader = sender as MultiThreadDownloader;
// 下载进度百分比
float percent = downloader.TotalProgress;
// 下载进度百分比
float percent = downloader.TotalProgress;
// 根据进度判断本次是否需要更新UI
if (Math.Abs(percent - downloading.Progress) < 0.01) { return; }
if (Math.Abs(percent - downloading.Progress) > 5) { return; }
// 根据进度判断本次是否需要更新UI
if (Math.Abs(percent - downloading.Progress) < 0.01) { return; }
if (Math.Abs(percent - downloading.Progress) > 5) { return; }
// 下载进度
downloading.Progress = percent;
// 下载进度
downloading.Progress = percent;
// 下载大小
downloading.DownloadingFileSize = Format.FormatFileSize(downloader.TotalBytesReceived) + "/" + Format.FormatFileSize(downloader.Size);
// 下载大小
downloading.DownloadingFileSize = Format.FormatFileSize(downloader.TotalBytesReceived) + "/" + Format.FormatFileSize(downloader.Size);
// 下载速度
long speed = (long)downloader.TotalSpeedInBytes;
// 下载速度
long speed = (long)downloader.TotalSpeedInBytes;
// 下载速度显示
downloading.SpeedDisplay = Format.FormatSpeed(speed);
// 下载速度显示
downloading.SpeedDisplay = Format.FormatSpeed(speed);
// 最大下载速度
if (downloading.Downloading.MaxSpeed < speed)
// 最大下载速度
if (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)
{
downloading.Downloading.MaxSpeed = speed;
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)
{
Core.Utils.Debugging.Console.PrintLine(e);
LogManager.Error(Tag, e);
Core.Utils.Debugging.Console.PrintLine($"{Tag}.DownloadCover()发生异常: {0}", e);
LogManager.Error($"{Tag}.DownloadCover()", e);
}
return null;
@ -378,20 +378,20 @@ namespace DownKyi.Services.Download
}
catch (InvalidOperationException e)
{
Core.Utils.Debugging.Console.PrintLine("Start DoWork()发生InvalidOperationException异常: {0}", e);
LogManager.Error("Start DoWork() InvalidOperationException", e);
Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork()发生InvalidOperationException异常: {0}", e);
LogManager.Error($"{Tag}.DoWork() InvalidOperationException", e);
}
catch (Exception e)
{
Core.Utils.Debugging.Console.PrintLine("Start DoWork()发生异常: {0}", e);
LogManager.Error("Start DoWork()", e);
Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork()发生异常: {0}", e);
LogManager.Error($"{Tag}.DoWork()", e);
}
// 判断是否该结束线程若为true跳出while循环
if (cancellationToken.IsCancellationRequested)
{
Core.Utils.Debugging.Console.PrintLine("AriaDownloadService: 下载服务结束跳出while循环");
LogManager.Debug(Tag, "下载服务结束");
Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork() 下载服务结束跳出while循环");
LogManager.Debug($"{Tag}.DoWork()", "下载服务结束");
break;
}
@ -409,8 +409,8 @@ namespace DownKyi.Services.Download
await Task.WhenAny(Task.WhenAll(downloadingTasks), Task.Delay(30000));
foreach (Task tsk in downloadingTasks.FindAll((m) => !m.IsCompleted))
{
Core.Utils.Debugging.Console.PrintLine("AriaDownloadService: 任务结束超时");
LogManager.Debug(Tag, "任务结束超时");
Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork() 任务结束超时");
LogManager.Debug($"{Tag}.DoWork()", "任务结束超时");
}
}

Loading…
Cancel
Save