public bool AskAndWait(string request, int delay) { lock (m_conditionWaiter) { try { AskingSomething = true; logger.Warn(request + Environment.NewLine + "[CANCEL IN " + delay + " SECONDS] (y/n)"); // Wait that user enter any characters if (ConditionWaiter.WaitFor(() => !EnteringCommand && Console.KeyAvailable, delay * 1000, AskWaiterInterval)) { // wait 'enter' var response = Console.ReadLine().ToLower(); AskingSomething = false; return(response == "y" || response == "yes"); } AskingSomething = false; return(false); } finally { AskingSomething = false; } } }
public void Shutdown() { bool flag = false; try { Monitor.Enter(this, ref flag); this.Running = false; this.OnShutdown(); GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine("Application is now terminated. Wait " + Definitions.ExitWaitTime + " seconds to exit ... or press any key to cancel"); if (ConditionWaiter.WaitFor(() => Console.KeyAvailable, Definitions.ExitWaitTime * 1000, 20)) { Console.ReadKey(true); Thread.Sleep(500); Console.WriteLine("Press now a key to exit..."); Console.ReadKey(true); } Environment.Exit(0); } finally { if (flag) { Monitor.Exit(this); } } }
public void Shutdown() { lock (this) { Running = false; OnShutdown(); GC.Collect(); GC.WaitForPendingFinalizers(); // We are done at this point. Console.WriteLine("Application is now terminated. Wait " + Definitions.ExitWaitTime + " seconds to exit ... or press any key to cancel"); if (IsNoExitShutdown) { Console.ReadKey(true); } if (ConditionWaiter.WaitFor(() => Console.KeyAvailable, Definitions.ExitWaitTime * 1000, 20)) { Console.ReadKey(true); Thread.Sleep(500); Console.WriteLine("Press now a key to exit..."); Console.ReadKey(true); } Environment.Exit(0); } }
public bool AskAndWait(string request, int delay) { bool result; lock (this.m_conditionWaiter) { try { this.AskingSomething = true; this.logger.Warn(string.Concat(new object[] { request, Environment.NewLine, "[CANCEL IN ", delay, " SECONDS] (y/n)" })); if (ConditionWaiter.WaitFor(() => !this.EnteringCommand && Console.KeyAvailable, delay * 1000, ConsoleBase.AskWaiterInterval)) { string a = Console.ReadLine().ToLower(); this.AskingSomething = false; result = (a == "y" || a == "yes"); } else { this.AskingSomething = false; result = false; } } finally { this.AskingSomething = false; } } return(result); }