F
fly_crane
Unregistered / Unconfirmed
GUEST, unregistred user!
三层的C/S结构,速度比较慢,特别是巢状数据(我们报名主从打印只支持巢状数据)。所以想在PROVIDER的打包过程上做优化,我在下面的这个函数:
function TEXDataPacketWriter.WriteDataSet(DataSet: TDataSet;
var Info: TEXInfoArray;
中创建多线程来完成数据的打包过程,并且在打包过程中终止主线程
while not ((WritePacketThread.Finished) and (WritePacketThread1.Finished))do
SuspendThread(MainThreadID);
ResumeThread(mainThreadID);
期待执行效果就想FLASHGET一样,多线程组织完数据,回到主线程中进行数据传输,但是当我创建单一进程的时候没有问题,运行的时候并不能把所有的数据巢状数据获取出来。我的线程创建如下:
constructor TWritePacketThread.CreateInstance(var Info: TEXInfoArray;DataSet: TDataSet;IDSWriter:IDSWriter;RecNo,RecsOut:Integer);
var i:integer;
begin
inherited Create(true);
FreeOnTerminate:=true;
FDataSet:=TADOQuery.Create(nil);
TAdoQuery(FDataSet).Connection:=TAdoQuery(DataSet).Connection;
TAdoQuery(FDataSet).SQL.text:=Trim(TAdoQuery(DataSet).SQL.Text);
FDataSet.Open;
FIDSWriter:=IDSWriter;
Finfo:=copy(Info,0,length(info));
FRecNo:=RecNo;
FRecsOut:=RecsOut;
FFinished:=FALSE;
Suspended:=FALSE;
end;
destructor TWritePacketThread.Destroy;
begin
//inherited Destroy;
FDataSet.Free;
inherited;
end;
procedure TWritePacketThread.Execute;
begin
if FDataSet.Active then
begin
SynMethod;
Finished:=TRUE;
end;
end;
procedure TWritePacketThread.SetFinished(const Value: Boolean);
begin
FFinished := Value;
end;
procedure TWritePacketThread.SynMethod;
const
B: Byte = 0;
var
Result,i:integer;
Flag:Boolean;
begin
//inherited;
Result:=0;
FDataSet.RecNo:=FRecNo;
Flag:=false;
while (not FDataSet.EOF) and (Result < FRecsOut)do
begin
FIDSWriter.PutField(fldIsChanged, 1, @B);
for i := 0 to High(FInfo)do
begin
if Flag then
begin
FInfo.DataSet.Next;
flag:=false;
end;
FInfo.PutProc(@FInfo);
end;
Inc(Result);
if Result < FRecsOut then
begin
fDataSet.Next;
end;
Flag:=true;
end;
end;
有哪位高手能帮我解决一下,不胜感谢。如果有更好的解决三层数据速度性能问题的方法,欢迎提出好的建议。
function TEXDataPacketWriter.WriteDataSet(DataSet: TDataSet;
var Info: TEXInfoArray;
中创建多线程来完成数据的打包过程,并且在打包过程中终止主线程
while not ((WritePacketThread.Finished) and (WritePacketThread1.Finished))do
SuspendThread(MainThreadID);
ResumeThread(mainThreadID);
期待执行效果就想FLASHGET一样,多线程组织完数据,回到主线程中进行数据传输,但是当我创建单一进程的时候没有问题,运行的时候并不能把所有的数据巢状数据获取出来。我的线程创建如下:
constructor TWritePacketThread.CreateInstance(var Info: TEXInfoArray;DataSet: TDataSet;IDSWriter:IDSWriter;RecNo,RecsOut:Integer);
var i:integer;
begin
inherited Create(true);
FreeOnTerminate:=true;
FDataSet:=TADOQuery.Create(nil);
TAdoQuery(FDataSet).Connection:=TAdoQuery(DataSet).Connection;
TAdoQuery(FDataSet).SQL.text:=Trim(TAdoQuery(DataSet).SQL.Text);
FDataSet.Open;
FIDSWriter:=IDSWriter;
Finfo:=copy(Info,0,length(info));
FRecNo:=RecNo;
FRecsOut:=RecsOut;
FFinished:=FALSE;
Suspended:=FALSE;
end;
destructor TWritePacketThread.Destroy;
begin
//inherited Destroy;
FDataSet.Free;
inherited;
end;
procedure TWritePacketThread.Execute;
begin
if FDataSet.Active then
begin
SynMethod;
Finished:=TRUE;
end;
end;
procedure TWritePacketThread.SetFinished(const Value: Boolean);
begin
FFinished := Value;
end;
procedure TWritePacketThread.SynMethod;
const
B: Byte = 0;
var
Result,i:integer;
Flag:Boolean;
begin
//inherited;
Result:=0;
FDataSet.RecNo:=FRecNo;
Flag:=false;
while (not FDataSet.EOF) and (Result < FRecsOut)do
begin
FIDSWriter.PutField(fldIsChanged, 1, @B);
for i := 0 to High(FInfo)do
begin
if Flag then
begin
FInfo.DataSet.Next;
flag:=false;
end;
FInfo.PutProc(@FInfo);
end;
Inc(Result);
if Result < FRecsOut then
begin
fDataSet.Next;
end;
Flag:=true;
end;
end;
有哪位高手能帮我解决一下,不胜感谢。如果有更好的解决三层数据速度性能问题的方法,欢迎提出好的建议。