From 680d2f4cd789edd11bd266057b9f9a68bef0f67e Mon Sep 17 00:00:00 2001 From: clragon Date: Wed, 20 Feb 2019 21:56:34 +0100 Subject: [PATCH] introduced waiting --- ExeToBat/BatGen.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ExeToBat/BatGen.cs b/ExeToBat/BatGen.cs index 4b7746b..442f71f 100644 --- a/ExeToBat/BatGen.cs +++ b/ExeToBat/BatGen.cs @@ -408,7 +408,7 @@ namespace ExeToBat else { Console.WriteLine("No files specified"); - new System.Threading.ManualResetEvent(false).WaitOne(500); + Wait(500); } @@ -460,6 +460,16 @@ namespace ExeToBat } + + public static void Wait(int ms) + { + using (System.Threading.ManualResetEvent wait = new System.Threading.ManualResetEvent(false)) + { + wait.WaitOne(ms); + } + } + + /// /// A function that displays a list as an enumerated menu on the Cli. Items can be chosen and will be processed by passed functions. /// Rest in peace, Cloe. @@ -536,7 +546,7 @@ namespace ExeToBat { Console.Write("{0}> {1}", Prompt, readInput); ConsoleKeyInfo input = Console.ReadKey(); - new System.Threading.ManualResetEvent(false).WaitOne(20); + Wait(20); int choiceNum = -1; switch (input) { @@ -631,7 +641,7 @@ namespace ExeToBat { Console.Write("{0}? [{1}]> ", title, "Y/N"); string Input = Console.ReadKey().KeyChar.ToString(); - new System.Threading.ManualResetEvent(false).WaitOne(20); + Wait(20); Console.Write("\n"); if (string.Equals(Input, "Y", StringComparison.OrdinalIgnoreCase)) { @@ -654,7 +664,7 @@ namespace ExeToBat public static void ResetInput(string error = "Input Invalid") { Console.Write(string.Format("[{0}] {1}", "Error", error)); - new System.Threading.ManualResetEvent(false).WaitOne(150); + Wait(150); ClearCurrentConsoleLine(); Console.SetCursorPosition(0, Console.CursorTop - 1); ClearCurrentConsoleLine();