From f0c0a5110819716e9bfffcaf7f22a681f5e4e88d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 23 Mar 2018 20:57:04 +0900 Subject: [PATCH] Convert APIAccess to use cancellation tokens --- osu.Game/Online/API/APIAccess.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index 39ecde55bc..957aeac3cd 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Net; using System.Threading; +using System.Threading.Tasks; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Logging; @@ -44,7 +45,7 @@ namespace osu.Game.Online.API protected bool HasLogin => Token != null || !string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password); - private readonly Thread thread; + private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource(); private readonly Logger log; @@ -58,8 +59,7 @@ namespace osu.Game.Online.API ProvidedUsername = config.Get(OsuSetting.Username); Token = config.Get(OsuSetting.Token); - thread = new Thread(run) { IsBackground = true }; - thread.Start(); + Task.Factory.StartNew(run, cancellationToken.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); } private readonly List components = new List(); @@ -92,7 +92,7 @@ namespace osu.Game.Online.API private void run() { - while (thread.IsAlive) + while (!cancellationToken.IsCancellationRequested) { switch (State) { @@ -310,7 +310,7 @@ namespace osu.Game.Online.API config.Save(); flushQueue(); - thread?.Abort(); + cancellationToken.Cancel(); } }