mirror of
https://github.com/ppy/osu.git
synced 2025-03-23 16:27:20 +08:00
Use ContinueWith, Check is Task empty
This commit is contained in:
parent
e4ebab92c6
commit
a38c6704c2
@ -9,7 +9,6 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -24,8 +23,6 @@ namespace osu.Game.Screens.Play
|
||||
private Task<ScoreInfo> saveFailedScoreTask;
|
||||
private ScoreInfo score;
|
||||
|
||||
private ScheduledDelegate saveScoreDelegate;
|
||||
|
||||
protected readonly Bindable<ImportState> State = new Bindable<ImportState>();
|
||||
|
||||
private DownloadButton button;
|
||||
@ -88,24 +85,19 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private void saveScore()
|
||||
{
|
||||
if (saveFailedScoreTask != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
State.Value = ImportState.Importing;
|
||||
|
||||
saveFailedScoreTask = Task.Run(ImportFailedScore);
|
||||
|
||||
saveScoreDelegate = new ScheduledDelegate(() =>
|
||||
saveFailedScoreTask.ContinueWith(s => Schedule(() =>
|
||||
{
|
||||
if (saveFailedScoreTask?.IsCompleted != true)
|
||||
// If the asynchronous preparation has not completed, keep repeating this delegate.
|
||||
return;
|
||||
|
||||
saveScoreDelegate?.Cancel();
|
||||
|
||||
score = saveFailedScoreTask.GetAwaiter().GetResult();
|
||||
|
||||
score = s.GetAwaiter().GetResult();
|
||||
State.Value = score != null ? ImportState.Imported : ImportState.Failed;
|
||||
}, Time.Current, 50);
|
||||
|
||||
Scheduler.Add(saveScoreDelegate);
|
||||
}));
|
||||
}
|
||||
|
||||
private void updateTooltip(ValueChangedEvent<ImportState> state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user