Beispiel #1
0
        private void HandleValidRedirectedInput(ref ConsoleInput redirectedInput)
        {
#if DEBUG
            const int STD_WAIT_TIME = 500;

            // Test for invalid in stream and replace with empty Text reader
            if (Console.IsInputRedirected)
            {
                var inputReceived = new AutoResetEvent(false);
                var inputThread   = new Thread(() =>
                {
                    try
                    {
                        Console.In.Peek();
                        inputReceived.Set();
                    }
                    catch (ThreadAbortException)
                    {
                        Thread.ResetAbort();
                    }
                })
                {
                    IsBackground = true
                };

                inputThread.Start();

                // Timeout expired?
                if (!inputReceived.WaitOne(STD_WAIT_TIME))
                {
                    // Gracefully stop the thread causing internal error.
                    redirectedInput = new ConsoleInput();
                }
            }
#endif
        }
Beispiel #2
0
 private void SetupInitialIO(ref ConsoleInput redirectedInput)
 {
     SetupConsoleLogger();
     HandleValidRedirectedInput(ref redirectedInput);
 }