AfxBeginThread
CWinThread*AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOIDpParam, int nPriority = THREAD_PRIORITY_NORMAL, UINTnStackSize = 0, DWORD dwCreateFlags = 0,LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
CWinThread*AfxBeginThread( CRuntimeClass* pThreadClass, intnPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize =0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTESlpSecurityAttrs = NULL );
CWinThread *m_pThread =AfxBeginThread(ThreadTest,0,THREAD_PRIORITY_HIGHEST,0,NULL);//调用测试线程
当线程弹出一个对话框再做相关操作时有可能会卡死的情况,这时我们可以在创建线程时调整一个线程的优先级,或者使用:SetThreadPriority指定优先级。
BOOL SetThreadPriority(HANDLE hThread, // handle to the threadint nPriority // thread priority level);功能说明设置指定线程的优先级参数说明线程优先级等级 | 标志 | 优先级值 | |
1 | idle (最低) | THREAD_PRIORITY_IDLE | 如果进程优先级为realtime则调整为16,其它情况为1 |
2 | LOWEST 低 | THREAD_PRIORITY_LOWEST | -2(在原有基础上-2) |
3 | BELOW 低于标准 | THREAD_PRIORITY_BELOW_NORMAL | -1(在原有基础上-1) |
4 | NORMAL(标准) | THREAD_PRIORITY_NORMAL | 不变(取进程优先级值) |
5 | ABOVE 高于标准 | THREAD_PRIORITY_ABOVE_NORMAL | +1(在原有基础上+1) |
6 | HIGHEST (高) | THREAD_PRIORITY_HIGHEST | +2(在原有基础上+2) |
7 | CRITICAL(最高) | THREAD_PRIORITY_TIME_CRITICAL | 如果进程优先级为realtime则调整为31,其它情况为15 |