多线程程序,被run函数阻塞
软件里面从CWinthread派生了一个线程,也重载了run函数
可是在主线程里面,执行run函数,却一定要等到run执行结束后,才能继续。
我希望的是启动这个线程后主线程立即可以干别的事情
我的code:
void dialog_realtime_show::OnBnClickedButton3()
{
CString text,caption;
caption="WARNING";
text="This action will kill all of RF card data from door camera\n";
text.LoadString(IDS_LONGTIME_HINT);
text+="Are you sure? (y/n)";
int a=MessageBox (text,caption,MB_ICONWARNING|MB_YESNO|MB_DEFBUTTON2);
if(a==IDYES)
{
#ifdef USE_DLG_THREAD
pATRT=new app_thread_read_attendance;
int a,b;
a=this->ssertup.SERIAL_PORT; b=this->ssertup.SERIAL_SPEED;
pATRT->setup_param(a,b,&this->edit_communication_status);
pATRT->m_pMainWnd=this;
pATRT->Run(); //准备在这里启动线程,没想到在这里阻塞了
//AfxBeginThread(*pATRT,GetSafeHwnd());
//AfxBeginThread(read_attendance,GetSafeHwnd());
#else
this->read_attendance();
#endif
}
else
return;
}
//=====================================
这是线程里面的模样:
int app_thread_read_attendance::Run(void)
{
int kkk=this->SERIAL_PORT+this->SERIAL_SPEED;
if(kkk>9600) //最少也要9600,如果大于,说明相应的参数被设置过了
{
this->read_attendance(); //这里要执行很久很久
}
else
return(-1);
return 0;
}