Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TreatControlCAsInput issue. Is this a bug?

Tags:

c#

.net

.net-4.0

Just ran across the problem described below. If "Console.TreatControlCAsInput = true;", you have to press [enter] twice on ReadLine().

I've written some demo code below. I am correct in surmising that this code demonstrate a bug in the .NET 4 framework?

        Console.Write("Test 1: Console.TreatControlCAsInput = false\nType \"hello\": ");
        {
            string readline = Console.ReadLine(); // type "hello" [enter].
            Console.WriteLine("You typed: {0}", readline);
            // Prints "hello".
        }

        Console.Write("Test 2: Console.TreatControlCAsInput = true\nType \"hello\": ");
        Console.TreatControlCAsInput = true;
        {
            string readline = Console.ReadLine(); // type "hello" [enter].
            Console.WriteLine("You typed: {0}", readline);
            // Should print "hello" - but instead, you have to press [enter] 
            // *twice* to complete the ReadLine() command, and it adds a "\r" 
            // rather than a "\n" to the output (so it overwrites the original line)
        }

        // This bug is a fatal error, because it makes all ReadLine() commands unusable.

        Console.Write("[any key to exit]");
        Console.ReadKey();
like image 769
Contango Avatar asked Nov 17 '11 14:11

Contango


2 Answers

It is a known issue with the Windows Console subsystem and has been reported on Microsoft Connect back in 2006.

Posted by Microsoft on 22/05/2007 at 12:37

Hello ARos, Thank you for reporting this issue in System.Console. The behavior exists with the Windows Console subsystem, as demonstrated with the attached Win32 C application. I have reported the issue to the Windows Console subsystem owner.

Thanks, Josh

like image 53
Johannes Kommer Avatar answered Nov 11 '22 01:11

Johannes Kommer


Not a bug on the Framework but it looks like a bug in the Windows console subsystem.

like image 36
Otávio Décio Avatar answered Nov 11 '22 01:11

Otávio Décio