Fix ongoing operation being begun in an async context

This commit is contained in:
Dean Herbert
2021-07-02 16:04:51 +09:00
parent f2d9d78455
commit 7b0f970e7d
2 changed files with 32 additions and 20 deletions

View File

@ -66,10 +66,12 @@ 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 = () => Task.Run(async () => OnReadyClick = () =>
{ {
readyClickOperation = OngoingOperationTracker.BeginOperation(); readyClickOperation = OngoingOperationTracker.BeginOperation();
Task.Run(async () =>
{
if (Client.IsHost && Client.LocalUser?.State == MultiplayerUserState.Ready) if (Client.IsHost && Client.LocalUser?.State == MultiplayerUserState.Ready)
{ {
await Client.StartMatch(); await Client.StartMatch();
@ -77,8 +79,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
await Client.ToggleReady(); await Client.ToggleReady();
readyClickOperation.Dispose(); readyClickOperation.Dispose();
}) });
}
}); });
}); });

View File

@ -70,22 +70,28 @@ 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 = () => Task.Run(async () => OnSpectateClick = () =>
{ {
readyClickOperation = OngoingOperationTracker.BeginOperation(); readyClickOperation = OngoingOperationTracker.BeginOperation();
Task.Run(async () =>
{
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 = () => Task.Run(async () => OnReadyClick = () =>
{ {
readyClickOperation = OngoingOperationTracker.BeginOperation(); readyClickOperation = OngoingOperationTracker.BeginOperation();
Task.Run(async () =>
{
if (Client.IsHost && Client.LocalUser?.State == MultiplayerUserState.Ready) if (Client.IsHost && Client.LocalUser?.State == MultiplayerUserState.Ready)
{ {
await Client.StartMatch(); await Client.StartMatch();
@ -93,8 +99,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
await Client.ToggleReady(); await Client.ToggleReady();
readyClickOperation.Dispose(); readyClickOperation.Dispose();
}) });
}
} }
} }
}; };