From 492c058e9b5fbb36be90627a4489ccad4123ac71 Mon Sep 17 00:00:00 2001 From: sheychen Date: Thu, 1 Dec 2016 10:55:20 +0100 Subject: [PATCH] No Thread.Sleep update --- Galactic Colors Control Common/Console.cs | 19 ++++++++++++------- Galactic Colors Control Common/Logger.cs | 1 - Galactic Colors Control/Program.cs | 8 ++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Galactic Colors Control Common/Console.cs b/Galactic Colors Control Common/Console.cs index 95e391b..4874785 100644 --- a/Galactic Colors Control Common/Console.cs +++ b/Galactic Colors Control Common/Console.cs @@ -9,6 +9,7 @@ namespace Galactic_Colors_Control_Common private static string inputBuffer = ""; private static List outputBuffer = new List(); public static string Title { get { return Cons.Title; } set { Cons.Title = value; } } + private static object locker = new object(); public static void Write(ColorStrings Text) { @@ -34,6 +35,7 @@ namespace Galactic_Colors_Control_Common inputBuffer += key.KeyChar; break; } + Update(); key = Cons.ReadKey(); } Cons.WriteLine(); @@ -44,13 +46,16 @@ namespace Galactic_Colors_Control_Common private static void Update() { - Cons.Clear(); - Cons.SetCursorPosition(0, 0); - foreach (ColorStrings output in outputBuffer) { output.Write(); } - SetInputPos(); - Cons.ForegroundColor = ConsoleColor.White; - Cons.BackgroundColor = ConsoleColor.Black; - Cons.Write("> " + inputBuffer); + lock (locker) + { + Cons.Clear(); + Cons.SetCursorPosition(0, 0); + foreach (ColorStrings output in outputBuffer) { output.Write(); } + SetInputPos(); + Cons.ForegroundColor = ConsoleColor.White; + Cons.BackgroundColor = ConsoleColor.Black; + Cons.Write("> " + inputBuffer); + } } private static void SetInputPos() diff --git a/Galactic Colors Control Common/Logger.cs b/Galactic Colors Control Common/Logger.cs index d97ffae..3c11208 100644 --- a/Galactic Colors Control Common/Logger.cs +++ b/Galactic Colors Control Common/Logger.cs @@ -164,7 +164,6 @@ namespace Galactic_Colors_Control_Common } toWriteLogs.Remove(log); } - Thread.Sleep(200); } } diff --git a/Galactic Colors Control/Program.cs b/Galactic Colors Control/Program.cs index 60ef4e8..4f64a84 100644 --- a/Galactic Colors Control/Program.cs +++ b/Galactic Colors Control/Program.cs @@ -27,17 +27,15 @@ namespace Galactic_Colors_Control { public int resultsBuffer; //Max amount of waiting results public int timeout; //Request timeout in ms - public int refresh; //Threads sleep in ms - public CoreConfig(int buffer, int time, int speed) + public CoreConfig(int buffer, int time) { resultsBuffer = buffer; timeout = time; - refresh = speed; } } - public CoreConfig config = new CoreConfig(20, 2000, 200); //Set default config + public CoreConfig config = new CoreConfig(20, 2000); //Set default config private int _errorCount = 0; //Leave if > 5 @@ -222,7 +220,6 @@ namespace Galactic_Colors_Control } } } - Thread.Sleep(config.refresh); } return new ResultData(req.id, ResultTypes.Error, Common.Strings("Timeout")); } @@ -313,7 +310,6 @@ namespace Galactic_Colors_Control break; } } - Thread.Sleep(config.refresh); } //TODOOutput.Add("/*exit*/"); }