//Show threads in the process
    AddText(hwnd,TEXT("\r\nThread Information:\r\n")TEXT("      TID     Priority\r\n"));
    THREADENTRY32 te={sizeof(te)};
    fOK=th.ThreadFirst(&te);
    for(;fOK;fOK=th.ThreadNext(&te))
    {
        if(te.th32OwnerProcessID==dwProcessID)
        {
            int nPriority=te.tpBasePri+te.tpDeltaPri;
            //下面4行代码为什么这么写?
            if ((te.tpBasePri < 16) && (nPriority > 15)) nPriority = 15;
            if ((te.tpBasePri > 15) && (nPriority > 31)) nPriority = 31;
            if ((te.tpBasePri < 16) && (nPriority <  1)) nPriority =  1;
            if ((te.tpBasePri > 15) && (nPriority < 16)) nPriority = 16;
            AddText(hwnd,TEXT("     %08X         %2d\r\n"),te.th32ThreadID,nPriority);       
        }
    
    }

解决方案 »

  1.   

    1,15,16,31这几个值是线程优先级的几个临界值,具体参考相关文档.深入浅出mfc中对此讲得比较详细
      

  2.   

    2楼 3KU   我找找看看 深入浅出mfc
      

  3.   

    看《Windows核心编程》上面有一章好像专门说线程优先级。
      

  4.   

    刚才在MSDN上查了查,没时间多看,贴一点相关你自己看:
    tpBasePri 
    Initial priority level assigned to a thread. This member can be one of the following values: Value Meaning 
    THREAD_PRIORITY_IDLE Indicates a base priority level of 1 for IDLE_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority level of 16 for REALTIME_PRIORITY_CLASS processes. 
    THREAD_PRIORITY_LOWEST Indicates 2 points below normal priority for the priority class. 
    THREAD_PRIORITY_BELOW_NORMAL Indicates one point below normal priority for the priority class. 
    THREAD_PRIORITY_NORMAL Indicates normal priority for the priority class. 
    THREAD_PRIORITY_ABOVE_NORMAL Indicates one point above normal priority for the priority class. 
    THREAD_PRIORITY_HIGHEST Indicates two points above normal priority for the priority class. 
    THREAD_PRIORITY_TIME_CRITICAL Indicates a base priority level of 15 for IDLE_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority level of 31 for REALTIME_PRIORITY_CLASS processes. tpDeltaPri 
    Change in the priority level of a thread. This value is a signed delta from the base priority level assigned to the thread.