Z
zxsdelphi
Unregistered / Unconfirmed
GUEST, unregistred user!
我用多线程发送数据的同时,向MEMO1显示发送的字符,会占用22%左右的CPU,如果不向MEMO1显示的话,CPU占有率不到1%,不知怎么回事?
procedure TxThread.Execute;
begin
//线程循环
{ Place thread code here }
repeat
sleep(5);
if DisplayStop=0 then
if QuestTime[ComNo]=0 then
synchronize(SendQuest);//(TxSendObj.QuestAllBw);
//(QuestAllBw1)
until Terminated;
end;
procedure TxThread.SendQuest();//所有的通讯请求
var
sbuf:array[0..250] of byte ;
Msg:TMyMsg;
i:integer;
begin
/ nd_ComBwflag[]
{ sbuf[0]:=setcom[ComNo][0];
for i:=1 to 255do
sbuf:=i;
}
form1.Memo1.Lines.Add('口');//就是这句不要的话,CPU占有率很小
QuestTime[ComNo]:=10;
//+inttostr(setcom[ComNo][0])+'已收到发送数据');
// sio_write(setcom[ComNo][0],@sbuf,256);
{
Msg.Msg:=2000+ComNo;
Msg.MsgLenth := ComNo;
unit1.TxSendObj.Dispatch(Msg) ;
}
end;
procedure TxThread.Execute;
begin
//线程循环
{ Place thread code here }
repeat
sleep(5);
if DisplayStop=0 then
if QuestTime[ComNo]=0 then
synchronize(SendQuest);//(TxSendObj.QuestAllBw);
//(QuestAllBw1)
until Terminated;
end;
procedure TxThread.SendQuest();//所有的通讯请求
var
sbuf:array[0..250] of byte ;
Msg:TMyMsg;
i:integer;
begin
/ nd_ComBwflag[]
{ sbuf[0]:=setcom[ComNo][0];
for i:=1 to 255do
sbuf:=i;
}
form1.Memo1.Lines.Add('口');//就是这句不要的话,CPU占有率很小
QuestTime[ComNo]:=10;
//+inttostr(setcom[ComNo][0])+'已收到发送数据');
// sio_write(setcom[ComNo][0],@sbuf,256);
{
Msg.Msg:=2000+ComNo;
Msg.MsgLenth := ComNo;
unit1.TxSendObj.Dispatch(Msg) ;
}
end;