I'm trying to create a console app with a thread but when I try to close the thread the Console.ReadLine()
blocks it. Do you know how to abort a Console.ReadLine()
or how to close a thread immediately? Here's my code:
public static void commandHandling()
{
while (Globals.running) // Globals is just a class where I have all of my global vars
{
string command = Console.ReadLine();
switch (command)
{
default:
Console.WriteLine("The command '" + command + "' cannot be found.");
break;
case "exit":
Main.Stop(); // Main is here the "control center" of the app
break;
}
}
}
Here starts the Thread:
Globals.cmdThread = new Thread(new ThreadStart(commandHandling));
Globals.cmdThread.Start();