diff --git a/ClientCore/SavedGameManager.cs b/ClientCore/SavedGameManager.cs index 8b6a8951c..855d147eb 100644 --- a/ClientCore/SavedGameManager.cs +++ b/ClientCore/SavedGameManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using Rampastring.Tools; namespace ClientCore @@ -10,7 +11,7 @@ namespace ClientCore /// public static class SavedGameManager { - private static bool saveRenameInProgress = false; + private static bool saveRenameInProgress; public static int GetSaveGameCount() { @@ -88,7 +89,7 @@ public static bool InitSavedGames() return true; } - public static void RenameSavedGame() + public static async ValueTask RenameSavedGameAsync() { Logger.Log("Renaming saved game."); @@ -149,7 +150,7 @@ public static void RenameSavedGame() return; } - System.Threading.Thread.Sleep(250); + await Task.Delay(250); } saveRenameInProgress = false; @@ -157,7 +158,7 @@ public static void RenameSavedGame() Logger.Log("Saved game SAVEGAME.NET succesfully renamed to " + Path.GetFileName(sgPath)); } - public static bool EraseSavedGames() + private static bool EraseSavedGames() { Logger.Log("Erasing previous MP saved games."); @@ -178,4 +179,4 @@ public static bool EraseSavedGames() return true; } } -} +} \ No newline at end of file diff --git a/DXMainClient/DXGUI/Multiplayer/GameLoadingLobbyBase.cs b/DXMainClient/DXGUI/Multiplayer/GameLoadingLobbyBase.cs index 9cb23cd03..6c507ed80 100644 --- a/DXMainClient/DXGUI/Multiplayer/GameLoadingLobbyBase.cs +++ b/DXMainClient/DXGUI/Multiplayer/GameLoadingLobbyBase.cs @@ -228,16 +228,14 @@ protected virtual ValueTask LeaveGameAsync() } private void fsw_Created(object sender, FileSystemEventArgs e) => - AddCallback(() => HandleFSWEvent(e)); + AddCallback(() => HandleFSWEventAsync(e).HandleTask()); - private void HandleFSWEvent(FileSystemEventArgs e) + private static async ValueTask HandleFSWEventAsync(FileSystemEventArgs e) { Logger.Log("FSW Event: " + e.FullPath); if (Path.GetFileName(e.FullPath) == "SAVEGAME.NET") - { - SavedGameManager.RenameSavedGame(); - } + await SavedGameManager.RenameSavedGameAsync(); } private async ValueTask BtnLoadGame_LeftClickAsync() diff --git a/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs b/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs index 0985a1dc2..4348dd4f0 100644 --- a/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs +++ b/DXMainClient/DXGUI/Multiplayer/GameLobby/MultiplayerGameLobby.cs @@ -205,11 +205,9 @@ protected void PostInitialize() } private void fsw_Created(object sender, FileSystemEventArgs e) - { - AddCallback(() => FSWEvent(e)); - } + => AddCallback(() => FSWEventAsync(e).HandleTask()); - private void FSWEvent(FileSystemEventArgs e) + private async ValueTask FSWEventAsync(FileSystemEventArgs e) { Logger.Log("FSW Event: " + e.FullPath); @@ -225,7 +223,7 @@ private void FSWEvent(FileSystemEventArgs e) gameSaved = true; - SavedGameManager.RenameSavedGame(); + await SavedGameManager.RenameSavedGameAsync(); } }