From 2d7024ffd92656a9d3646abc0e87111709e6bfe4 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 28 Aug 2019 01:14:35 +0300 Subject: [PATCH] Use CancellationTokenSource to avoid unwanted panels creation --- osu.Game/Overlays/SocialOverlay.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 5ed6a9a703..ee3adf65b9 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -17,6 +17,7 @@ using osu.Game.Overlays.Social; using osu.Game.Users; using osu.Framework.Threading; using System; +using System.Threading; namespace osu.Game.Overlays { @@ -92,6 +93,8 @@ namespace osu.Game.Overlays private void queueUpdate() => Scheduler.AddOnce(updateSearch); + private CancellationTokenSource loadCancellation; + private void updateSearch() { Scheduler.CancelDelayedTasks(); @@ -132,6 +135,8 @@ namespace osu.Game.Overlays return; } + loadCancellation = new CancellationTokenSource(); + var newPanels = new FillFlowContainer { RelativeSizeAxes = Axes.X, @@ -167,7 +172,7 @@ namespace osu.Game.Overlays { loading.Hide(); ScrollFlow.Add(panels = newPanels); - }); + }, loadCancellation.Token); } private void updateUsers(IEnumerable newUsers) @@ -212,6 +217,8 @@ namespace osu.Game.Overlays { loading.Show(); + loadCancellation?.Cancel(); + if (panels != null) { panels.Expire();