我设置了两个线程,一个优先级是Normal,一个是Highest,但是执行结果是:先执行Normal的线程,然后才是Highest的线程.在Debug时候,却是正常的,为什么!!!.
源代码如下:
using System;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
public static Thread worker;
public static Thread worker2;
static void Main(string[] args)
{
Console.WriteLine("Entering void Main()");
worker = new Thread(new ThreadStart(FindPriority));
worker2 = new Thread(new ThreadStart(FindPriority));
worker.Name = "FindPriority() Thread";
worker2.Name = "FindPriority() Thread 2";
worker2.Priority = System.Threading.ThreadPriority.Highest;
// worker.Priority = ThreadPriority.Lowest;
worker.Start();
worker2.Start();
Console.WriteLine("Exiting void Main()");
}
public static void FindPriority()
{
Thread t;
t = Thread.CurrentThread;
Console.WriteLine("Name: " + t.Name);
Console.WriteLine("State: " + t.ThreadState.ToString());
Console.WriteLine("Priority: " + t.Priority.ToString());
if (t.Priority == ThreadPriority.Highest)
{
Console.ReadLine();
}
}
}
}