线程自动关闭
在主程序开始运行就建立了一个线程,处理采集回来的数据队列,只要是通过两个变量来.如下:
//创建线程
HANDLE hThread;
DWORD ThreadID;
hThread=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)ThreadFunc,NULL,0, &ThreadID);
void ThreadFunc( )
{
CCollector * pWin= (CCollector*)AfxGetApp()->m_pMainWnd;
//执行采集结束存储过程
while(1)
{
if ( nGatherFlag == 0 )
{
//获取列表中的IP地址
CString strListIP,strList;
int nCurrentRow = 0;
while(nCurrentRow < pWin->m_ListCount)
{
//LIST控件上的地址
strListIP = pWin->m_List.GetItemText(nCurrentRow,1);
if ( strList.GetLength() > 0 )
{
strList = "'" + strListIP + "'," + strList;
}
else
{
strList = "'" + strListIP + "'";
}
nCurrentRow++;
}
//查询采集数据队列的数据是否清理完成
CString strSql;
strSql.Format(" select cj_date from cj_line with(nolock) where cj_ip in ( %s ) ",strList);
pRecordsetDB->Open(_variant_t(strSql),_variant_t((IDispatch*)pConnectDB,true),adOpenStatic,adLockOptimistic,adCmdText);
if( pRecordsetDB->adoEOF )
{
pRecordsetDB->Close();
//设置队列清空标识
nGatherOver = 1;
break;
}
pRecordsetDB->Close();
}
pWin->TransDataToTable();
Sleep(1000);
}
}
当按下按钮代码如下:
nGatherFlag = 0;
//查询采集数据队列的数据是否清理完成
while(1)
{
if( nGatherOver == 1)
{
break;
}
Sleep(10000);
}
线程怎么就关闭不运行了.为什么呢,请各位大虾帮忙看看.