L
lyshw
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个Client程序,每5s发送一次数据,
发送时我先建一线程,然后在线程中connect和发送
但是任务管理器中显示的线程数一直在增加,请各位老师给与帮助
constructor TSendThread.Create();
begin
FtcpClient := TIdTCPClient.Create(nil);
FtcpClient.Host := Config.BlackListIP;
FtcpClient.Port := Config.BlackListPort;
PlateImg := TMemoryStream.Create;
VehicleImg := TMemoryStream.Create;
inherited Create(True);
end;
destructor TSendThread.Destroy;
begin
FtcpClient.Free;
PlateImg.Free;
VehicleImg.Free;
inherited;
end;
procedure TSendThread.Execute;
var
m: TMemoryStream;
begin
FreeOnTerminate := True;
try
FtcpClient.Connect;
m := TMemoryStream.Create;
try
m.Write(FData, SizeOf(FData));
//发送车辆数据
FtcpClient.WriteStream(m, True, True);
if TPackFunction(FData.FunID) = pfNew then
begin
//发送车牌图
FtcpClient.WriteStream(PlateImg, True, True);
FtcpClient.WriteStream(VehicleImg, True, True);
FMsg := '发送黑(白)名单完毕';
end else
FMsg := '重新发送车牌完毕';
FLogType := ltNormal;
Synchronize(ShowMsg);
finally
m.Free;
FtcpClient.Disconnect;
end;
except
on E: Exceptiondo
begin
WriteLog('异常, 原因:' + e.Message);
FMsg := '连接黑(白)名单计算机失败';
FLogType := ltError;
Synchronize(ShowMsg);
end;
end;
end;
procedure TSendThread.ShowMsg;
begin
frmMain.ShowLog(FMsg, FLogType);
end;
发送时我先建一线程,然后在线程中connect和发送
但是任务管理器中显示的线程数一直在增加,请各位老师给与帮助
constructor TSendThread.Create();
begin
FtcpClient := TIdTCPClient.Create(nil);
FtcpClient.Host := Config.BlackListIP;
FtcpClient.Port := Config.BlackListPort;
PlateImg := TMemoryStream.Create;
VehicleImg := TMemoryStream.Create;
inherited Create(True);
end;
destructor TSendThread.Destroy;
begin
FtcpClient.Free;
PlateImg.Free;
VehicleImg.Free;
inherited;
end;
procedure TSendThread.Execute;
var
m: TMemoryStream;
begin
FreeOnTerminate := True;
try
FtcpClient.Connect;
m := TMemoryStream.Create;
try
m.Write(FData, SizeOf(FData));
//发送车辆数据
FtcpClient.WriteStream(m, True, True);
if TPackFunction(FData.FunID) = pfNew then
begin
//发送车牌图
FtcpClient.WriteStream(PlateImg, True, True);
FtcpClient.WriteStream(VehicleImg, True, True);
FMsg := '发送黑(白)名单完毕';
end else
FMsg := '重新发送车牌完毕';
FLogType := ltNormal;
Synchronize(ShowMsg);
finally
m.Free;
FtcpClient.Disconnect;
end;
except
on E: Exceptiondo
begin
WriteLog('异常, 原因:' + e.Message);
FMsg := '连接黑(白)名单计算机失败';
FLogType := ltError;
Synchronize(ShowMsg);
end;
end;
end;
procedure TSendThread.ShowMsg;
begin
frmMain.ShowLog(FMsg, FLogType);
end;