WEB开发网
开发学院软件开发VC VC++实现多线程的调度和处理 阅读

VC++实现多线程的调度和处理

 2010-07-20 20:44:59 来源:WEB开发网   
核心提示:该函数的实现代码为:void CMutexesDlg::AddToListBox(LPCTSTR szBuffer){CListBox* pBox = (CListBox*) GetDlgItem(IDC_DATABOX);ASSERT(pBox != NULL);if (pBox != NULL){int x = p

该函数的实现代码为:

void CMutexesDlg::AddToListBox(LPCTSTR szBuffer)
{
CListBox* pBox = (CListBox*) GetDlgItem(IDC_DATABOX);
ASSERT(pBox != NULL);
if (pBox != NULL){
int x = pBox- >AddString(szBuffer);
pBox- >SetCurSel(x);
if (pBox- >GetCount() > 100)
pBox- >DeleteString(0);
}
}
---- 然后利用ClassWizard 填加用于调整进程优先级、两个线程优先级以及用于复选线程挂起的函数。

调整进程优先级的代码为:

void CMutexesDlg::OnSelchangePriorityclass()
{
DWORD dw;
//取焦点选项
CComboBox* pBox = (CComboBox*)
GetDlgItem(IDC_PRIORITYCLASS);
int nCurSel = pBox- >GetCurSel();
switch (nCurSel)
{
case 0:
dw = IDLE_PRIORITY_CLASS;break;
case 1:
default:
dw = NORMAL_PRIORITY_CLASS;break;
case 2:
dw = HIGH_PRIORITY_CLASS;break;
case 3:
dw = REALTIME_PRIORITY_CLASS;break;
}
SetPriorityClass(GetCurrentProcess(), dw);//调整优先级
}

由于调整两个线程优先级的代码基本相似,单独设置一个函数根据不同的ID 来调整线程优先级。该函数代码为:

void CMutexesDlg::OnPriorityChange(UINT nID)
{
ASSERT(nID == IDC_CNTRTHRDPRIORITY ||
nID == IDC_DSPYTHRDPRIORITY);
DWORD dw;
//取对应该ID的焦点选项
CComboBox* pBox = (CComboBox*) GetDlgItem(nID);
int nCurSel = pBox- >GetCurSel();
switch (nCurSel)
{
case 0:
dw = (DWORD)THREAD_PRIORITY_IDLE;break;
case 1:
dw = (DWORD)THREAD_PRIORITY_LOWEST;break;
case 2:
dw = (DWORD)THREAD_PRIORITY_BELOW_NORMAL;break;
case 3:
default:
dw = (DWORD)THREAD_PRIORITY_NORMAL;break;
case 4:
dw = (DWORD)THREAD_PRIORITY_ABOVE_NORMAL;break;
case 5:
dw = (DWORD)THREAD_PRIORITY_HIGHEST;break;
case 6:
dw = (DWORD)THREAD_PRIORITY_TIME_CRITICAL;break;
}
if (nID == IDC_CNTRTHRDPRIORITY)
m_pCounterThread- >SetThreadPriority(dw);
//调整计数线程优先级
else
m_pDisplayThread- >SetThreadPriority(dw);
//调整显示线程优先级
}

上一页  2 3 4 5 6 7 8  下一页

Tags:VC 实现 线程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接