I have to create this console based application and I have this problem: I have created something like a KeyListener using multithreading (can't do simple loop, because there is a second thread running simultaneously). And the loop in a thread needs to check if pressed key is an integer.
What is that I don't understand?
The way I get this: there is an infinite loop within the thread that tries to capture the input and if the input == 1
it writes text in the console.
What am I missing?
static void KeyRead()
{
do
{
int i = (int) Console.ReadKey().KeyChar;
if (i == 1) {
Console.Out.Write("Key 1 pressed");
}
} while (true);
}
static void Main(string[] args)
{
Thread keyListner = new Thread(new ThreadStart(KeyRead));
keyListner.Start();
}