Fix some incorrectly invoked async calls

This commit is contained in:
Dean Herbert
2021-07-02 14:43:48 +09:00
parent 7b4317be9a
commit f2d9d78455
4 changed files with 14 additions and 8 deletions

View File

@ -116,7 +116,7 @@ namespace osu.Desktop.Updater
if (scheduleRecheck) if (scheduleRecheck)
{ {
// check again in 30 minutes. // check again in 30 minutes.
Scheduler.AddDelayed(async () => await checkForUpdateAsync().ConfigureAwait(false), 60000 * 30); Scheduler.AddDelayed(() => Task.Run(async () => await checkForUpdateAsync().ConfigureAwait(false)), 60000 * 30);
} }
} }
@ -141,7 +141,7 @@ namespace osu.Desktop.Updater
Activated = () => Activated = () =>
{ {
updateManager.PrepareUpdateAsync() updateManager.PrepareUpdateAsync()
.ContinueWith(_ => updateManager.Schedule(() => game.GracefullyExit())); .ContinueWith(_ => updateManager.Schedule(() => game?.GracefullyExit()));
return true; return true;
}; };
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -65,7 +66,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(200, 50), Size = new Vector2(200, 50),
OnReadyClick = async () => OnReadyClick = () => Task.Run(async () =>
{ {
readyClickOperation = OngoingOperationTracker.BeginOperation(); readyClickOperation = OngoingOperationTracker.BeginOperation();
@ -77,7 +78,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
await Client.ToggleReady(); await Client.ToggleReady();
readyClickOperation.Dispose(); readyClickOperation.Dispose();
} })
}); });
}); });

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -69,19 +70,19 @@ namespace osu.Game.Tests.Visual.Multiplayer
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(200, 50), Size = new Vector2(200, 50),
OnSpectateClick = async () => OnSpectateClick = () => Task.Run(async () =>
{ {
readyClickOperation = OngoingOperationTracker.BeginOperation(); readyClickOperation = OngoingOperationTracker.BeginOperation();
await Client.ToggleSpectate(); await Client.ToggleSpectate();
readyClickOperation.Dispose(); readyClickOperation.Dispose();
} })
}, },
readyButton = new MultiplayerReadyButton readyButton = new MultiplayerReadyButton
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(200, 50), Size = new Vector2(200, 50),
OnReadyClick = async () => OnReadyClick = () => Task.Run(async () =>
{ {
readyClickOperation = OngoingOperationTracker.BeginOperation(); readyClickOperation = OngoingOperationTracker.BeginOperation();
@ -93,7 +94,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
await Client.ToggleReady(); await Client.ToggleReady();
readyClickOperation.Dispose(); readyClickOperation.Dispose();
} })
} }
} }
}; };

View File

@ -491,6 +491,10 @@ namespace osu.Game
public override Task Import(params ImportTask[] imports) public override Task Import(params ImportTask[] imports)
{ {
// encapsulate task as we don't want to begin the import process until in a ready state. // encapsulate task as we don't want to begin the import process until in a ready state.
// ReSharper disable once AsyncVoidLambda
// TODO: This is bad because `new Task` doesn't have a Func<Task?> override.
// Only used for android imports and a bit of a mess. Probably needs rethinking overall.
var importTask = new Task(async () => await base.Import(imports).ConfigureAwait(false)); var importTask = new Task(async () => await base.Import(imports).ConfigureAwait(false));
waitForReady(() => this, _ => importTask.Start()); waitForReady(() => this, _ => importTask.Start());