diff --git a/MCGalaxy/Commands/building/CmdImageprint.cs b/MCGalaxy/Commands/building/CmdImageprint.cs
index 53509d503..ae270d56f 100644
--- a/MCGalaxy/Commands/building/CmdImageprint.cs
+++ b/MCGalaxy/Commands/building/CmdImageprint.cs
@@ -104,9 +104,9 @@ namespace MCGalaxy.Commands.Building {
bool DoImage(Player p, Vec3S32[] m, object state, BlockID block) {
if (m[0].X == m[1].X && m[0].Z == m[1].Z) { p.Message("No direction was selected"); return false; }
- Thread thread = new Thread(() => DoDrawImage(p, m, (DrawArgs)state));
- thread.Name = "ImagePrint";
- thread.Start();
+ Thread thread;
+ Server.StartThread(out thread, "ImagePrint",
+ () => DoDrawImage(p, m, (DrawArgs)state));
return false;
}
diff --git a/MCGalaxy/Games/RoundsGame/RoundsGame.cs b/MCGalaxy/Games/RoundsGame/RoundsGame.cs
index c5a165029..35f07aac1 100644
--- a/MCGalaxy/Games/RoundsGame/RoundsGame.cs
+++ b/MCGalaxy/Games/RoundsGame/RoundsGame.cs
@@ -81,9 +81,8 @@ namespace MCGalaxy.Games
if (pl.level == Map) PlayerJoinedGame(pl);
}
- Thread t = new Thread(RunGame);
- t.Name = "Game_" + GameName;
- t.Start();
+ Thread thread;
+ Server.StartThread(out thread, "Game_ " + GameName, RunGame);
}
/// Attempts to auto start this game with infinite rounds.
diff --git a/MCGalaxy/Levels/Level.Physics.cs b/MCGalaxy/Levels/Level.Physics.cs
index 7354c383a..85831a8d3 100644
--- a/MCGalaxy/Levels/Level.Physics.cs
+++ b/MCGalaxy/Levels/Level.Physics.cs
@@ -55,10 +55,9 @@ namespace MCGalaxy {
lock (physThreadLock) {
if (physThread != null && physThread.ThreadState == ThreadState.Running) return;
if (ListCheck.Count == 0 || physThreadStarted) return;
-
- physThread = new Thread(PhysicsLoop);
- physThread.Name = "Physics_" + name;
- physThread.Start();
+
+ Server.StartThread(out physThread, "Physics_" + name,
+ PhysicsLoop);
physThreadStarted = true;
}
}
diff --git a/MCGalaxy/Modules/Relay/RelayBot.cs b/MCGalaxy/Modules/Relay/RelayBot.cs
index 143934e59..10bb66323 100644
--- a/MCGalaxy/Modules/Relay/RelayBot.cs
+++ b/MCGalaxy/Modules/Relay/RelayBot.cs
@@ -235,10 +235,8 @@ namespace MCGalaxy.Modules.Relay
/// Starts the read loop in a background thread
void RunAsync() {
- worker = new Thread(IOThread);
- worker.Name = RelayName + "_RelayBot";
- worker.IsBackground = true;
- worker.Start();
+ Server.StartThread(out worker, RelayName + "_RelayBot",
+ IOThread);
}
protected abstract void DoConnect();
diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs
index b3e267eea..18acb3256 100644
--- a/MCGalaxy/Player/Player.Handlers.cs
+++ b/MCGalaxy/Player/Player.Handlers.cs
@@ -521,10 +521,8 @@ namespace MCGalaxy
callback = ExecuteSerialCommands;
}
- Thread thread = new Thread(callback);
- try { thread.Name = "CMD_" + cmd; } catch { }
- thread.IsBackground = true;
- thread.Start();
+ Thread thread;
+ Server.StartThread(out thread, "CMD_ " + cmd, callback);
} catch (Exception e) {
Logger.LogError(e);
Message("&WCommand failed");
@@ -548,10 +546,9 @@ namespace MCGalaxy
messages.Add(args); commands.Add(command);
}
- Thread thread = new Thread(() => UseCommands(commands, messages, data));
- thread.Name = "CMDS_";
- thread.IsBackground = true;
- thread.Start();
+ Thread thread;
+ Server.StartThread(out thread, "CMDS_",
+ () => UseCommands(commands, messages, data));
} catch (Exception e) {
Logger.LogError(e);
Message("&WCommand failed.");
diff --git a/MCGalaxy/Server/Server.cs b/MCGalaxy/Server/Server.cs
index c6d4ff7fe..a1145182d 100644
--- a/MCGalaxy/Server/Server.cs
+++ b/MCGalaxy/Server/Server.cs
@@ -335,6 +335,14 @@ namespace MCGalaxy
sw.Elapsed.TotalMilliseconds, end / 1024.0, deltaKB);
}
+ public static void StartThread(out Thread thread, string name, ThreadStart threadFunc) {
+ thread = new Thread(threadFunc);
+
+ thread.IsBackground = true;
+ try { thread.Name = name; } catch { }
+ thread.Start();
+ }
+
// only want ASCII alphanumerical characters for salt
static bool AcceptableSaltChar(char c) {
diff --git a/MCGalaxy/util/Threading/AsyncWorker.cs b/MCGalaxy/util/Threading/AsyncWorker.cs
index 3a74835be..f52152927 100644
--- a/MCGalaxy/util/Threading/AsyncWorker.cs
+++ b/MCGalaxy/util/Threading/AsyncWorker.cs
@@ -66,10 +66,8 @@ namespace MCGalaxy
/// Starts the background worker thread
public void RunAsync() {
- Thread worker = new Thread(SendLoop);
- worker.Name = ThreadName;
- worker.IsBackground = true;
- worker.Start();
+ Thread worker;
+ Server.StartThread(out worker, ThreadName, SendLoop);
}
public void StopAsync() {
diff --git a/MCGalaxy/util/Threading/Scheduler.cs b/MCGalaxy/util/Threading/Scheduler.cs
index 6eef064a9..51b536941 100644
--- a/MCGalaxy/util/Threading/Scheduler.cs
+++ b/MCGalaxy/util/Threading/Scheduler.cs
@@ -32,9 +32,7 @@ namespace MCGalaxy.Tasks {
volatile SchedulerTask curTask; // for .ToString()
public Scheduler(string name) {
- thread = new Thread(Loop);
- thread.Name = name;
- thread.Start();
+ Server.StartThread(out thread, name, Loop);
}