C++多線程學習

void lpRecvProc(LPVOID lpParam)
{
 CEdit* pEdit=(CEdit*)lpParam;
 long j;
 CString str;
 pEdit->GetWindowText(str);
 j=atoi(str);
 for(int i=0;i<100000;i++)
 {
  j++;
  CString str1;
  str1.Format("%d",j);
  pEdit->SetWindowText(str1);
 }
}
void CThreadTestDlg::OnStartbutton()
{
 // TODO: Add your control notification handler code here
 //先終止先前的進程
 if(hThread)
  TerminateThread(hThread,dwThreadId);

 hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)lpRecvProc,&m_edit,0,&dwThreadId);
 if(hThread==NULL)
  AfxMessageBox("創建線程失敗!");
}

void CThreadTestDlg::OnEndbutton()
{
 // TODO: Add your control notification handler code here
 if(hThread)
  TerminateThread(hThread,dwThreadId);
}

void CThreadTestDlg::OnPausebutton()
{
 // TODO: Add your control notification handler code here
 if(hThread)
  SuspendThread(hThread);
}

void CThreadTestDlg::OnContinuebutton()
{
 // TODO: Add your control notification handler code here
 if(hThread)
  ResumeThread(hThread);
}

void CThreadTestDlg::OnDestroy()
{
 CDialog::OnDestroy();
 
 // TODO: Add your message handler code here
 if(hThread)
  TerminateThread(hThread,dwThreadId);
}

發佈了80 篇原創文章 · 獲贊 0 · 訪問量 31萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章