c#如何立即终止线程? /如何中止Console.ReadLine?

时间:2015-04-28 15:56:00

标签: c# multithreading

我试图用线程创建一个控制台应用程序但是当我尝试关闭线程时Console.ReadLine()阻止它。你知道如何中止Console.ReadLine()或如何立即关闭一个线程吗?这是我的代码:

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;
        }
    }
}

这里启动线程: Globals.cmdThread = new Thread(new ThreadStart(commandHandling)); Globals.cmdThread.Start();

0 个答案:

没有答案