Thread的优先级
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int i = 0, j = 0;
Thread t1 = new Thread(() =>
{
while (true)
{
i++;
}
});
Thread t2 = new Thread(() =>
{
while (true)
{
j++;
}
});
t1.Priority = ThreadPriority.Highest; //将t1这个线程的优先级设为最高
t2.Priority = ThreadPriority.Lowest; //将t2这个线程的优先级设为最低
t1.Start(); //
t2.Start();
Thread.Sleep(3000);
Console.WriteLine("i=" + i + " j=" + j);
Console.ReadKey();
}
}
}