多线程技术(四)线程的优先级
线程是根据其优先级来调度的,每个线程都有特定的优先级。每个线程在创建时其优先级为:
ThreadPriority.Normal
线程的优先级定义为ThreadPriority枚举类型,如下表:
例题3:修改上述例题,对Main()方法做如下修改,观察修改线程的优先级的效果:
ThreadStart workerStart = new ThreadStart(DisplayNumbers);
Thread workerThread = new Thread(workerStart);
workerThread.Name = "Worker Thread";
workerThread.Priority=ThreadPriority.AboveNormal;
结果:
一旦工作线程被启动,主线程不再运行,直到工作线程结束后主线程才重新计算。