下载列表监听事件优化

pull/409/head
leiurayer 3 years ago
parent a8ac5cea9b
commit 661a6cc477

@ -1,4 +1,5 @@
using DownKyi.Core.Settings; using DownKyi.Core.Logging;
using DownKyi.Core.Settings;
using DownKyi.Services; using DownKyi.Services;
using DownKyi.Utils; using DownKyi.Utils;
using Prism.Commands; using Prism.Commands;
@ -40,22 +41,13 @@ namespace DownKyi.ViewModels.DownloadManager
{ {
// 初始化DownloadedList // 初始化DownloadedList
DownloadedList = App.DownloadedList; DownloadedList = App.DownloadedList;
DownloadedList.CollectionChanged += new NotifyCollectionChangedEventHandler(async (object sender, NotifyCollectionChangedEventArgs e) => DownloadedList.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
{
await Task.Run(() =>
{ {
if (e.Action == NotifyCollectionChangedAction.Add) if (e.Action == NotifyCollectionChangedAction.Add)
{ {
foreach (var item in DownloadedList) SetDialogService();
{
if (item != null && item.DialogService == null)
{
item.DialogService = dialogService;
}
}
} }
}); });
});
SetDialogService(); SetDialogService();
DownloadFinishedSort finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort(); DownloadFinishedSort finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort();
@ -143,6 +135,8 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion #endregion
private async void SetDialogService() private async void SetDialogService()
{
try
{ {
await Task.Run(() => await Task.Run(() =>
{ {
@ -155,6 +149,12 @@ namespace DownKyi.ViewModels.DownloadManager
} }
}); });
} }
catch (Exception e)
{
Core.Utils.Debugging.Console.PrintLine("SetDialogService()发生异常: {0}", e);
LogManager.Error($"{Tag}.SetDialogService()", e);
}
}
public override void OnNavigatedFrom(NavigationContext navigationContext) public override void OnNavigatedFrom(NavigationContext navigationContext)
{ {

@ -1,4 +1,5 @@
using DownKyi.Images; using DownKyi.Core.Logging;
using DownKyi.Images;
using DownKyi.Models; using DownKyi.Models;
using DownKyi.Services; using DownKyi.Services;
using DownKyi.Utils; using DownKyi.Utils;
@ -34,22 +35,13 @@ namespace DownKyi.ViewModels.DownloadManager
{ {
// 初始化DownloadingList // 初始化DownloadingList
DownloadingList = App.DownloadingList; DownloadingList = App.DownloadingList;
DownloadingList.CollectionChanged += new NotifyCollectionChangedEventHandler(async (object sender, NotifyCollectionChangedEventArgs e) => DownloadingList.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
{
await Task.Run(() =>
{ {
if (e.Action == NotifyCollectionChangedAction.Add) if (e.Action == NotifyCollectionChangedAction.Add)
{ {
foreach (var item in DownloadingList) SetDialogService();
{
if (item != null && item.DialogService == null)
{
item.DialogService = dialogService;
}
}
} }
}); });
});
SetDialogService(); SetDialogService();
} }
@ -181,6 +173,8 @@ namespace DownKyi.ViewModels.DownloadManager
#endregion #endregion
private async void SetDialogService() private async void SetDialogService()
{
try
{ {
await Task.Run(() => await Task.Run(() =>
{ {
@ -193,6 +187,12 @@ namespace DownKyi.ViewModels.DownloadManager
} }
}); });
} }
catch (Exception e)
{
Core.Utils.Debugging.Console.PrintLine("SetDialogService()发生异常: {0}", e);
LogManager.Error($"{Tag}.SetDialogService()", e);
}
}
public override void OnNavigatedFrom(NavigationContext navigationContext) public override void OnNavigatedFrom(NavigationContext navigationContext)
{ {

Loading…
Cancel
Save