TreatControlCAsInput问题。这是错误吗? [英] TreatControlCAsInput issue. Is this a bug?

查看:156
本文介绍了TreatControlCAsInput问题。这是错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅遇到以下问题。如果 Console.TreatControlCAsInput = true;,则必须在ReadLine()上按两次[enter]。

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

我在下面编写了一些演示代码。我以为该代码演示了.NET 4框架中的错误?

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


推荐答案

它是已知问题,并且早在2006年就已在Microsoft Connect上进行报道。

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


Microsoft于2007年5月22日12:37发布

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

Hello ARos ,感谢您在System.Console中报告此问题。 Windows控制台子系统存在
行为,如附带的Win32 C应用程序所示的
。我已将问题报告给Windows控制台子系统所有者

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.

感谢Josh

这篇关于TreatControlCAsInput问题。这是错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆