Add ability to perform clean-up code before quitting (#1561)

* Add ability to perform clean-up code before quitting
* Move to WinAPI namespace
This commit is contained in:
ReinforceZwei 2021-05-01 22:56:31 +08:00 committed by GitHub
parent 750684e010
commit 0400ad89ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 0 deletions

View file

@ -150,6 +150,15 @@ namespace MinecraftClient
{
RequestPassword();
}
// Setup exit cleaning code
ExitCleanUp.Add(delegate ()
{
// Do NOT use Program.Exit() as creating new Thread cause program to freeze
if (client != null) { client.Disconnect(); ConsoleIO.Reset(); }
if (offlinePrompt != null) { offlinePrompt.Abort(); offlinePrompt = null; ConsoleIO.Reset(); }
if (Settings.playerHeadAsIcon) { ConsoleIcon.revertToMCCIcon(); }
});
startupargs = args;