线程的优先级是各线程质检相对执行的先后顺序,它决定了各线程之间相对的优先级,设置线程的优先级是通过Thread.Priority枚举值来实现的
1.Higest:最高值。
2.ABoveNormal:向于正常值。
3.Normal:正常值。
4.Below Normal:低于正常值。
5.Lowest:最低值。
分别创建两个线程,然后通过设定不同的优先级来显示线程的名称和优先级
class Program { public static void moth() { Console.WriteLine("线程名称{0}",Thread.CurrentThread.Name.ToString()); Console.WriteLine("线程优先级{0}", Thread.CurrentThread.Priority.ToString()); } static void Main(string[] args) { ThreadStart s1 = new ThreadStart(moth); ThreadStart s2 = new ThreadStart(moth); Thread th = new Thread(s1); Thread th2 = new Thread(s2); th.Name = "华腾线程1"; th2.Name = "华腾线程2"; th.Priority = ThreadPriority.Highest; th.Start(); th2.Start(); Console.Read(); } }