查询信息 出现系统阻塞现象
请教大家:
时时查询信息是要在不断的运行的,但是那样会不断的占用资源,所以会出现阻塞现象
我现在把那时时查询写在了线程里 也把显示数据的也一起写在了线程里,可是还是会出
现阻塞现象,为什么呢?
下面是部分代码:
void __fastcall QueryThread::Execute(){ //---- Place thread code here ---- Synchronize(QueryData); if(pkgBuf->SetPackage(Form1->ReadBuffer)!=S_OK)return; Synchronize(QueryProc1);}//---------------------------------------void __fastcall QueryThread::QueryData(){ long Length; Form1->QueryTime->Enabled = false; setmem(Form1->WriteBuffer,64,0); pkgBuf->SetCommand(0xa1); pkgBuf->SetDataLength(0x00); pkgBuf->SetSlaveAddr(Form1->SlaveAddr->Text.ToInt()); pkgBuf->GetPackage(Form1->WriteBuffer); comm->Write(Length,&dwWriteLength); Form1->QueryTime->Enabled = true;}void __fastcall QueryThread::QueryProc1() //查询协议 普通信息{ AnsiString str; unsigned char Data[64]; unsigned short *p; unsigned long *l; SYSTEMTIME systime; setmem(Data,64,0); pkgBuf->GetData(Data); p= (unsigned short*)&Data[0]; //直流电压 str = *p; str = str.Insert(".",str.Length()); if(str.Pos(".") == 1)str = "0" + str; Form1->vlQuery->Cells[1][1] = str+"V"; .........}