TreatControlCAsInput issue. Is this a bug?

怎甘沉沦 提交于 2019-12-10 12:35:14

问题


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();

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/8168754/treatcontrolcasinput-issue-is-this-a-bug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!