C#控制台程序 - 停止STDIN进入STDOUT

时间:2022-11-20 00:05:07

I'm writing a simple console app in C#, .NET 2.0. It starts new threads using a threading timer, while it interprets commands on the main thread.

我正在用C#,.NET 2.0编写一个简单的控制台应用程序。它使用线程计时器启动新线程,同时解释主线程上的命令。

I currently take three commands: P - Pause C - Continue Q - Quit

我目前采取三个命令:P - 暂停C - 继续Q - 退出

This functionality works quite well, but unfortunately when I type P, C, or Q (or any other character for that matter), the character goes to STDOUT. Is there a way I can stop this programatically? Also it'd be useful to know if I could disable and re-enable STDIN -> STDOUT.

此功能运行良好,但不幸的是,当我键入P,C或Q(或任何其他字符)时,字符转到STDOUT。有没有办法我可以以编程方式停止这个?知道我是否可以禁用和重新启用STDIN - > STDOUT也很有用。

Thanks in advance.

提前致谢。

1 个解决方案

#1


Sounds like you are using

听起来像你在使用

Console.ReadKey();

Which clearly states in the documentation that it prints to the screen and if you don't want to output to the screen you should use the overloaded version

在文档中明确指出它打印到屏幕上,如果你不想输出到屏幕,你应该使用重载版本

Console.ReadKey(true);

Which does not output.

哪个不输出。

#1


Sounds like you are using

听起来像你在使用

Console.ReadKey();

Which clearly states in the documentation that it prints to the screen and if you don't want to output to the screen you should use the overloaded version

在文档中明确指出它打印到屏幕上,如果你不想输出到屏幕,你应该使用重载版本

Console.ReadKey(true);

Which does not output.

哪个不输出。