Fix AutoRelog retry accounting

This commit is contained in:
Anon 2026-06-02 10:24:59 +02:00
parent f39fe2d067
commit 47de24cf1d
2 changed files with 113 additions and 21 deletions

View file

@ -899,12 +899,25 @@ namespace MinecraftClient
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
/// <param name="keepAccountAndServerSettings">Optional, keep account and server settings</param>
public static void Restart(int delaySeconds = 0, bool keepAccountAndServerSettings = false)
{
TryRestart(delaySeconds, keepAccountAndServerSettings);
}
internal static bool HasRestartPendingForAnotherThread
{
get
{
lock (_restartLock)
return HasRestartPendingForAnotherThreadNoLock();
}
}
internal static bool TryRestart(int delaySeconds = 0, bool keepAccountAndServerSettings = false)
{
lock (_restartLock)
{
if (_restartThread is not null && _restartThread.IsAlive
&& _restartThread != Thread.CurrentThread)
return;
if (HasRestartPendingForAnotherThreadNoLock())
return false;
ConsoleIO.Backend?.StopReadThread();
var thread = new Thread(new ThreadStart(delegate
@ -938,9 +951,17 @@ namespace MinecraftClient
}));
_restartThread = thread;
thread.Start();
return true;
}
}
private static bool HasRestartPendingForAnotherThreadNoLock()
{
return _restartThread is not null
&& _restartThread.IsAlive
&& _restartThread != Thread.CurrentThread;
}
public static void DoExit(int exitcode = 0)
{
WriteBackSettings();