mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Use single function for most thread creation
This commit is contained in:
parent
cc9a71bc1b
commit
07a1bd8925
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary> Attempts to auto start this game with infinite rounds. </summary>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -235,10 +235,8 @@ namespace MCGalaxy.Modules.Relay
|
||||
|
||||
/// <summary> Starts the read loop in a background thread </summary>
|
||||
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();
|
||||
|
@ -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.");
|
||||
|
@ -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) {
|
||||
|
@ -66,10 +66,8 @@ namespace MCGalaxy
|
||||
|
||||
/// <summary> Starts the background worker thread </summary>
|
||||
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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user