多线程编程,多线程编程注意要点

1.不能直接中断线程,应该设置一个标记,线程运行时检查这个标记
void CThreadSoap::ThreadRun()
{
RESULTTYPE rc(RC_SUCCESS);
//线程是否运行线程
bool is_run(false);
//线程要执行的动作
long thread_action(0);
//要执行动作的参数
void *lpActionPara( NULL );
//窗体句柄
HWND hWnd( NULL );
//gSaop对象
struct soap gSoap;
//获取线程是否运行
rc = this->CheckStatus( is_run,thread_action,&hWnd,&lpActionPara);
if( RC_SUCCESS != rc )
{
this->SetThreadError(rc);
return;
}
::soap_init(&gSoap);
while( is_run )
{
//检查是否执行动作
if( 0 != thread_action )
{
this->CallSoap( thread_action, gSoap,hWnd,lpActionPara );
this->ResetThreadAction();
this->SafePostMessage(hWnd,WM_SAOP_DONE,thread_action);
}
else
{
::Sleep(1);
}
//释放资源
hWnd = NULL;
CThreadBase::SafeFreeObject(lpActionPara);
//获取线程是否继续运行
rc = this->CheckStatus( is_run,thread_action,&hWnd,&lpActionPara);
if( RC_SUCCESS != rc )
{
this->SetThreadError( rc);
break;
}
}
//释放资源
CThreadBase::SafeFreeObject(lpActionPara);
::soap_done(&gSoap);
}
Tags:  多线程编程要点 vc多线程编程 多线程编程

延伸阅读

最新评论

发表评论