2

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.

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

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.

Thanks in advance.

C. Ross
  • 31,137
  • 42
  • 147
  • 238
  • C# doesn't refer to it as STDIN and STDOUT. – George Stocker Feb 04 '09 at 13:14
  • I don't think you're asking the right question. Are you upset that whenever you press a key it's echo'd? Console.Read() is used to read in characters, and unless you tell it otherwise, it'll be echo'd into STDOUT (which is normal). – George Stocker Feb 04 '09 at 13:16

1 Answers1

9

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.

Robert MacLean
  • 38,975
  • 25
  • 98
  • 152