mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-08-03 19:36:14 -04:00
Fix rarely throwing error due to trying to set IsBackground on a dead thread
This commit is contained in:
parent
3401665c67
commit
9cb2cf1637
@ -107,7 +107,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
Thread thread;
|
||||
Server.StartThread(out thread, "ImagePrint",
|
||||
() => DoDrawImage(p, m, (DrawArgs)state));
|
||||
thread.IsBackground = true;
|
||||
Utils.SetBackgroundMode(thread);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ namespace MCGalaxy.Games
|
||||
|
||||
Thread thread;
|
||||
Server.StartThread(out thread, "Game_ " + GameName, RunGame);
|
||||
thread.IsBackground = true;
|
||||
Utils.SetBackgroundMode(thread);
|
||||
}
|
||||
|
||||
/// <summary> Attempts to auto start this game with infinite rounds. </summary>
|
||||
|
@ -58,7 +58,7 @@ namespace MCGalaxy {
|
||||
|
||||
Server.StartThread(out physThread, "Physics_" + name,
|
||||
PhysicsLoop);
|
||||
physThread.IsBackground = true;
|
||||
Utils.SetBackgroundMode(physThread);
|
||||
physThreadStarted = true;
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ namespace MCGalaxy.Modules.Relay
|
||||
void RunAsync() {
|
||||
Server.StartThread(out worker, RelayName + "_RelayBot",
|
||||
IOThread);
|
||||
worker.IsBackground = true;
|
||||
Utils.SetBackgroundMode(worker);
|
||||
}
|
||||
|
||||
protected abstract void DoConnect();
|
||||
|
@ -558,7 +558,7 @@ namespace MCGalaxy
|
||||
|
||||
Thread thread;
|
||||
Server.StartThread(out thread, "CMD_ " + cmd, callback);
|
||||
thread.IsBackground = true;
|
||||
Utils.SetBackgroundMode(thread);
|
||||
} catch (Exception e) {
|
||||
Logger.LogError(e);
|
||||
Message("&WCommand failed");
|
||||
@ -585,7 +585,7 @@ namespace MCGalaxy
|
||||
Thread thread;
|
||||
Server.StartThread(out thread, "CMDS_",
|
||||
() => UseCommands(commands, messages, data));
|
||||
thread.IsBackground = true;
|
||||
Utils.SetBackgroundMode(thread);
|
||||
} catch (Exception e) {
|
||||
Logger.LogError(e);
|
||||
Message("&WCommand failed.");
|
||||
|
@ -68,7 +68,7 @@ namespace MCGalaxy
|
||||
public void RunAsync() {
|
||||
Thread worker;
|
||||
Server.StartThread(out worker, ThreadName, SendLoop);
|
||||
worker.IsBackground = true;
|
||||
Utils.SetBackgroundMode(worker);
|
||||
}
|
||||
|
||||
public void StopAsync() {
|
||||
|
@ -83,7 +83,7 @@ namespace MCGalaxy.UI
|
||||
Logger.Log(LogType.CommandUsage, "(console): FAILED COMMAND");
|
||||
}
|
||||
});
|
||||
thread.IsBackground = true;
|
||||
Utils.SetBackgroundMode(thread);
|
||||
}
|
||||
|
||||
public static string Format(string message) {
|
||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace MCGalaxy
|
||||
{
|
||||
@ -92,5 +93,11 @@ namespace MCGalaxy
|
||||
static char HexEncode(int i) {
|
||||
return i < 10 ? (char)(i + '0') : (char)((i - 10) + 'a');
|
||||
}
|
||||
|
||||
public static void SetBackgroundMode(Thread thread) {
|
||||
// Throws an exception when called on a dead thread,
|
||||
// which can very rarely happen
|
||||
try { thread.IsBackground = true; } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user