AfxBeginThread开辟线程的问题,一段时间后无法创建?
本帖最后由 VisualEleven 于 2013-06-28 13:56:29 编辑 各位好!我现在遇到了一个问题,想请教大家一下。
我使用
CWinThread *pGcodeWorkerMDI;
pGcodeWorkerMDI=AfxBeginThread( (AFX_THREADPROC) ThreadProcHob,this); 开辟的线程。
if (pGcodeWorkerMDI == NULL)
{
AfxMessageBox(L"代码下发线程创建失败!",MB_OK|MB_ICONERROR);
return;
}
UINT WINAPI ThreadProcHob(MCUOutputBufType* lpParam)
{
int i=0;
int unHandValue=0;
theApp.m_writeGCode.InitHardware();
while(1)
{
unHandValue=theApp.m_writeGCode.SiglReadHPI32Bit(0x8834);//读取DSP 缓冲区空闲状态0x55555555;
if (unHandValue==0x55555555)//如果空闲则可以发送数据
{
while(i<NumLine)//当为M02时则结束循环
{
theApp.m_writeGCode.HPIBlockWrite(0x8834,(ULONG *)&m_myOutputBuf[i],sizeof(m_myOutputBuf[i])/4);//发送数据
unHandValue=theApp.m_writeGCode.SiglReadHPI32Bit(0x8834);//读取缓冲区状态
i++;
if(unHandValue==0xaaaaaaaa)//如果忙碌 则一直读取缓冲区状态 直到缓冲区空闲
{
do
{
unHandValue=theApp.m_writeGCode.SiglReadHPI32Bit(0x8834);
}
while(unHandValue!=0x55555555);
}
if(m_myOutputBuf[i-1].Data[0]==0x4D000000&&m_myOutputBuf[i-1].Data[1]==0x02000000)
{
break;
}
}
break;
}
Sleep(30);
}
memset(m_myOutputBuf,0,sizeof(MCUOutputBufType)*25);//清空数组m_myOutputBuf
NumLine=0;//清空加工代码总行号
theApp.m_writeGCode.CloseHardware();
return 0;
}