private async void GetRankingAll() { if (CallSideBar.IsChecked != false) { CallSideBar.IsChecked = false; Toggle(this, new RoutedEventArgs()); } CurrectMode = "Ranking"; ModeText.Text = "今日排行榜"; Brush Highlightcolor = new SolidColorBrush(Color.FromArgb(255, 0, 134, 245)); iconRanking.Foreground = Highlightcolor; textRanking.Foreground = Highlightcolor; // 老夫要性能优化 ItemCollection temp = listbox.Items; listbox.ItemsSource = null; Loading.Start(); await Task.Run(async() => { for (int i = 0; i < temp.Count; i++) { #if DEBUG Console.WriteLine(GC.GetGeneration(temp[i])); #endif ((WorkShow)(temp[i])).Dispose(); ((List <WorkShow>)(listbox.ItemsSource)).Remove((WorkShow)(temp[i])); } GC.SuppressFinalize(temp); FlushMemory.Flush(); Paginated <Rank> shit = await AT.T.GetRankingAllAsync("daily", 1, 20); listbox.Dispatcher.Invoke(() => { List <WorkShow> l = new List <WorkShow>(); foreach (Rank r in shit) { foreach (RankWork w in r.Works) { long workid = 0; long userid = 0; bool isliked = false; if (w.Work.Id != null) { workid = (long)w.Work.Id; } if (w.Work.User.Id != null) { userid = (long)w.Work.User.Id; } if (w.Work.FavoriteId != null) { isliked = true; } if (!File.Exists(string.Format("{0}\\cache\\{1}_preview.png", Environment.CurrentDirectory, workid))) { XLEngine.AddToTask(w.Work.ImageUrls.Medium, string.Format("{0}\\cache\\{1}_preview.png", Environment.CurrentDirectory, workid)); } l.Add(new WorkShow(w.Work.Title, workid, w.Work.User.Name, userid, isliked, w.Work.ImageUrls.Medium)); } } listbox.ItemsSource = l; }); }); await Task.Delay(1000); Loading.Stop(); }
private async void GetMyFavoriteWorks() { if (CallSideBar.IsChecked != false) { CallSideBar.IsChecked = false; Toggle(this, new RoutedEventArgs()); } CurrectMode = "MyFavoriteWorks"; ModeText.Text = "我的收藏"; Brush Highlightcolor = new SolidColorBrush(Color.FromArgb(255, 255, 67, 67)); iconMyFavoriteWorks.Foreground = Highlightcolor; textMyFavoriteWorks.Foreground = Highlightcolor; ItemCollection temp = listbox.Items; listbox.ItemsSource = null; Loading.Start(); await Task.Run(async() => { // 看上面 for (int i = 0; i < temp.Count; i++) { #if DEBUG Console.WriteLine(string.Format("[DEBUG] GC GEN for Work Obj :{0}", GC.GetGeneration(temp[i]))); #endif ((WorkShow)(temp[i])).Dispose(); ((List <WorkShow>)(listbox.ItemsSource)).Remove((WorkShow)(temp[i])); } GC.SuppressFinalize(temp); FlushMemory.Flush(); Pixeez.Objects.Paginated <Pixeez.Objects.UsersFavoriteWork> shit = await AT.T.GetMyFavoriteWorksAsync(); listbox.Dispatcher.Invoke(() => { List <WorkShow> l = new List <WorkShow>(); foreach (Pixeez.Objects.UsersFavoriteWork w in shit) { long workid = 0; long userid = 0; bool isliked = false; if (w.Work.Id != null) { workid = (long)w.Work.Id; } if (w.Work.User.Id != null) { userid = (long)w.Work.User.Id; } isliked = true; if (!File.Exists(string.Format("{0}\\cache\\{1}_preview.png", Environment.CurrentDirectory, workid))) { XLEngine.AddToTask(w.Work.ImageUrls.Medium, string.Format("{0}\\cache\\{1}_preview.png", Environment.CurrentDirectory, workid)); } l.Add(new WorkShow(w.Work.Title, workid, w.Work.User.Name, userid, isliked, w.Work.ImageUrls.Medium)); } listbox.ItemsSource = l; }); }); await Task.Delay(1000); Loading.Stop(); }