首页 > 其他 > 详细

AfxBeginThread、AfxEndThread、GetExitCodeThread的配合使用

时间:2021-05-28 11:30:19      阅读:10      评论:0      收藏:0      [点我收藏+]
    //线程入口函数(全局)
    UINT MyThreadProc(LPVOID pParam)
    {
        //在需要添加返回值的地方
        if (...)
        {
            AfxEndThread(0);
            return 0;
        }

        if (...)
        {
            AfxEndThread(1);
            return 1;
        }
        ...
    }


    //在主线程中创建线程,并获取线程函数的返回值
    CWinThread* pThread = AfxBeginThread(MyThreadProc, NULL, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
    pThread->m_bAutoDelete = FALSE;//设置不自动释放
    pThread->ResumeThread();//恢复运行
    WaitForSingleObject(pThread->m_hThread, -1);//等待运行结束
    DWORD dwResult(0);
    BOOL flag = ::GetExitCodeThread(pThread->m_hThread, &dwResult);//执行成功返回TRUE,否则为FALSE. dwResult存储线程函数的返回值
    if (dwResult == 0)
    {
        ...
    }
    else if (dwResult == 1)
    {
        ...
    }

参考链接:

https://blog.csdn.net/qq_22034437/article/details/52711043

https://blog.csdn.net/xbmoxia/article/details/16985953

AfxBeginThread、AfxEndThread、GetExitCodeThread的配合使用

原文:https://www.cnblogs.com/rcg714786690/p/14820869.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!