我写了一个简单的多线程片段只是为了让自己习惯这个概念。
public void testThread(int arg1, ConsoleColor color)
{
for (int i = 0; i < 1000; i++)
{
Console.ForegroundColor = color;
Console.WriteLine("Thread " + color.ToString() + " : " + i);
Console.ResetColor();
Thread.Sleep(arg1);
}
}
Thread t1 = new Thread(() => program.testThread(1000, ConsoleColor.Blue));
Thread t2 = new Thread(() => program.testThread(1000, ConsoleColor.Red));
t1.Start();
t2.Start();
t1.Join();
t2.Join();
我在输出控制台窗口中看到的是
我只是不明白为什么有时用红色装饰的线会变成白色或浅灰色(无论如何)。你能帮助启发这个想法吗?
提前致谢。