From 99b3e5393d60fe9d37c169daac3739fc701109a5 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sat, 12 Mar 2022 23:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96UI=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi/ViewModels/ViewMySpaceViewModel.cs | 25 ++++++++++++++++++-- DownKyi/ViewModels/ViewUserSpaceViewModel.cs | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/DownKyi/ViewModels/ViewMySpaceViewModel.cs b/DownKyi/ViewModels/ViewMySpaceViewModel.cs index 58d2f23..01a8d94 100644 --- a/DownKyi/ViewModels/ViewMySpaceViewModel.cs +++ b/DownKyi/ViewModels/ViewMySpaceViewModel.cs @@ -12,6 +12,7 @@ using Prism.Events; using Prism.Regions; using System; using System.Collections.ObjectModel; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; @@ -22,6 +23,8 @@ namespace DownKyi.ViewModels { public const string Tag = "PageMySpace"; + private CancellationTokenSource tokenSource; + // mid private long mid = -1; @@ -291,6 +294,9 @@ namespace DownKyi.ViewModels /// private void ExecuteBackSpace() { + // 结束任务 + tokenSource?.Cancel(); + NavigationParam parameter = new NavigationParam { ViewName = ParentView, @@ -415,6 +421,7 @@ namespace DownKyi.ViewModels /// private async void UpdateSpaceInfo() { + bool isCancel = false; bool isNoData = true; Uri toutuUri = null; string headerUri = null; @@ -423,6 +430,8 @@ namespace DownKyi.ViewModels await Task.Run(() => { + CancellationToken cancellationToken = tokenSource.Token; + // 背景图片 SpaceSettings spaceSettings = Core.BiliApi.Users.UserSpace.GetSpaceSettings(mid); if (spaceSettings != null) @@ -505,7 +514,19 @@ namespace DownKyi.ViewModels // 没有数据 isNoData = true; } - }); + + // 判断是否该结束线程 + if (cancellationToken.IsCancellationRequested) + { + isCancel = true; + } + }, (tokenSource = new CancellationTokenSource()).Token); + + // 是否该结束线程 + if (isCancel) + { + return; + } // 是否获取到数据 if (isNoData) @@ -528,7 +549,7 @@ namespace DownKyi.ViewModels // 性别 Sex = sexUri == null ? null : new BitmapImage(sexUri); // 等级 - Level = new BitmapImage(levelUri); + Level = levelUri == null ? null : new BitmapImage(levelUri); ArrowBack.Fill = DictionaryResource.GetColor("ColorText"); Logout.Fill = DictionaryResource.GetColor("ColorText"); diff --git a/DownKyi/ViewModels/ViewUserSpaceViewModel.cs b/DownKyi/ViewModels/ViewUserSpaceViewModel.cs index 0770e55..9cecb51 100644 --- a/DownKyi/ViewModels/ViewUserSpaceViewModel.cs +++ b/DownKyi/ViewModels/ViewUserSpaceViewModel.cs @@ -353,7 +353,7 @@ namespace DownKyi.ViewModels // 性别 Sex = sexUri == null ? null : new BitmapImage(sexUri); // 等级 - Level = new BitmapImage(levelUri); + Level = levelUri == null ? null : new BitmapImage(levelUri); ArrowBack.Fill = DictionaryResource.GetColor("ColorText"); TopNavigationBg = DictionaryResource.GetColor("ColorMask100");