天下

记录修行的印记

MFC 线程代码片段

貌似 挂起线程 必须在主界面的UI线程去操作

UINT UiThreadProcessProtocol(LPVOID lParam)
{
    CCalcPPIView
* view = (CCalcPPIView*)lParam;
    DmcControler
* Dmc = &(view->Dmc);

    
while (1)
    {
        
//AfxTrace("%u \n",GetTickCount());
        Sleep(500);
    } 
    
return 0;
}

CWinThread
* m_ThreadProcessProtocol;
m_ThreadProcessProtocol 
= AfxBeginThread(UiThreadProcessProtocol,this);

void CCalcPPIView::OnBtnRegulate()
{
    
if (m_ThreadProcessProtocol!=NULL) {
        m_ThreadProcessProtocol
->SuspendThread();
        AfxTrace(
"SuspendThread() at %u \n",GetTickCount());
    }
    
    {
        CRegulate dlg(
this);
        dlg.DoModal();
    }
    
if (m_ThreadProcessProtocol!=NULL) {
        m_ThreadProcessProtocol
->ResumeThread();
        AfxTrace(
"ResumeThread() at %u \n",GetTickCount());
    }
}

void CCalcPPIView::CloseDevice(BOOL bUpdateUI )
{
    CCalcPPIView
* view = this;
    AfxTrace(
"CCalcPPIView::CloseDevice() Entry \n");

    Dmc.SetOpened(
0);

    
if (view->m_ThreadProcessProtocol!=NULL) {
        WaitForSingleObject(view
->m_ThreadProcessProtocol->m_hThread,INFINITE);
        view
->m_ThreadProcessPro NULL;
    }
}

 

 

posted on 2016-12-13 10:09 天下 阅读(285) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2016年9月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论