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();
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
Not a bug on the Framework but it looks like a bug in the Windows console subsystem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With