From 4eca66a024cd7d00b034db8093e5e1637053576c Mon Sep 17 00:00:00 2001 From: Tyler Watson Date: Tue, 10 May 2016 23:45:14 +1000 Subject: [PATCH] Removed ThreadPool threads in favour of plain threads. See NyxStudios/TerrariaAPI-Server@b1d62b6cbd60b6d83400680eda632d465411e9a9 for details. --- TShockAPI/BackupManager.cs | 11 +++++++++-- TShockAPI/StatTracker.cs | 14 ++++++++++---- TShockAPI/TShockAPI.csproj | 19 +++++++------------ TShockAPI/UpdateManager.cs | 12 ++++++++++-- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/TShockAPI/BackupManager.cs b/TShockAPI/BackupManager.cs index f8f6b449..d484c389 100644 --- a/TShockAPI/BackupManager.cs +++ b/TShockAPI/BackupManager.cs @@ -44,8 +44,15 @@ namespace TShockAPI public void Backup() { lastbackup = DateTime.UtcNow; - ThreadPool.QueueUserWorkItem(DoBackup); - ThreadPool.QueueUserWorkItem(DeleteOld); + Thread t = new Thread(() => { + DoBackup(null); + DeleteOld(null); + }); + t.Name = "Backup Thread"; + t.Start(); + + // ThreadPool.QueueUserWorkItem(DoBackup); + // ThreadPool.QueueUserWorkItem(DeleteOld); } private void DoBackup(object o) diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index 6156a2cb..62c11283 100755 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -37,13 +37,21 @@ namespace TShockAPI { initialized = true; serverId = Guid.NewGuid().ToString(); // Gets reset every server restart - ThreadPool.QueueUserWorkItem(SendUpdate); + // ThreadPool.QueueUserWorkItem(SendUpdate); + Thread t = new Thread(() => { + do { + Thread.Sleep(1000 * 60 * 5); + SendUpdate(null); + } while(true); + }); + t.IsBackground = true; + t.Name = "TShock Stat Tracker Thread"; + t.Start(); } } private void SendUpdate(object info) { - Thread.Sleep(1000 * 60 * 5); JsonData data; if(ServerApi.RunningMono) @@ -105,8 +113,6 @@ namespace TShockAPI failed = true; } } - - ThreadPool.QueueUserWorkItem(SendUpdate); } } diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 21ce6172..5fd57361 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {49606449-072B-4CF5-8088-AA49DA586694} Library Properties @@ -62,21 +60,18 @@ ..\prebuilts\Mono.Data.Sqlite.dll - - False - ..\prebuilts\MySql.Data.dll - True - ..\prebuilts\BCrypt.Net.dll - - False - ..\prebuilts\Newtonsoft.Json.dll - + + ..\prebuilts\MySql.Data.dll + + + ..\prebuilts\Newtonsoft.Json.dll + @@ -180,7 +175,7 @@ - {6877506e-adc6-4142-98a6-79e4fa02855a} + {6877506E-ADC6-4142-98A6-79E4FA02855A} TerrariaServer diff --git a/TShockAPI/UpdateManager.cs b/TShockAPI/UpdateManager.cs index e782095c..0884cb77 100755 --- a/TShockAPI/UpdateManager.cs +++ b/TShockAPI/UpdateManager.cs @@ -36,7 +36,16 @@ namespace TShockAPI public UpdateManager() { - ThreadPool.QueueUserWorkItem(CheckForUpdates); + Thread t = new Thread(() => { + do { + CheckForUpdates(null); + } while (true); + }); + + t.Name = "TShock Update Thread"; + t.IsBackground = true; + + t.Start(); } private void CheckForUpdates(object state) @@ -53,7 +62,6 @@ namespace TShockAPI } Thread.Sleep(CheckXMinutes * 60 * 1000); - ThreadPool.QueueUserWorkItem(CheckForUpdates); } public void UpdateCheck(object o)