0

my question is how to disable fully the input for a console application.

Its for a TCP Server and i dont want to enter somethinks in the console.

at the moment i have:

for (int i = 0; i < 500; i++){
    Console.ReadKey(true);
}

But this not working really good ( Must wait of press enter 500 times and then the application can be continue ).

Sorry for my bad english, hope someone can help me.

Best wishes

EastMile
  • 23
  • 7
  • Possible duplicate of [Disabling User Input in a Console Application](http://stackoverflow.com/questions/32532024/disabling-user-input-in-a-console-application) – dippas Mar 23 '17 at 18:48

1 Answers1

0

In this example Console.ReadKey(true) will itercept the pressed key and wont display the user's input

class Writer
{
    public void WriteLine(string myText)
    {
        for (int i = 0; i < myText.Length; i++)
        {
            if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Enter)
            {
                Console.Write(myText.Substring(i, myText.Length - i));
                break;
            }
            Console.Write(myText[i]);
            System.Threading.Thread.Sleep(pauseTime);
        }
        Console.WriteLine("");
    }
}
Rohit Poudel
  • 1,793
  • 2
  • 20
  • 24