我线程代码如下.constructor TuploadTread.Create(DBSc,DBLocal:TDatabase;qySc,qyLocal:TQuery);
begin
fDBSc := DBSc;
fDBLocal := DBLocal;
fQySc := qySc;
fqyLocal :=qyLocal;
fTableList := TStringList.Create;
inherited Create(true);
FreeOnTerminate := true; // Thread Free Itself when terminated
Suspended := true; // Continue the thread
end;
procedure TuploadTread.Execute;
begin
while not Terminated do
doUpload;//执行查询更新远程数据库的操作.
end;关于调用:
function TFBase.UploadToSc(tableList:TStringList):boolean;
begin
if uploadThread = nil then
begin
uploadThread := TuploadTread.Create(DMData.DatabaseSC,DMData.DatabaseThread,DMData.qySc,DMData.qyLocal);
uploadThread.fTableList := tableList;
uploadThread.Priority := tpLower;//tpIdle;//
uploadThread.OnTerminate:=FreeThread;
uploadThread.Resume;
end;
end;
问题:
1、当主线程调用以后,如果再执行与数据库相关的工作会变的非常的慢。
2、如果网络不通的话,系统就会等待数十秒才会执行。
如何解决这些问题呢?
我只是想在这些传输动作不要影响到主线程的正常工作才加入线程的。
希望有高手能够解决。!
begin
fDBSc := DBSc;
fDBLocal := DBLocal;
fQySc := qySc;
fqyLocal :=qyLocal;
fTableList := TStringList.Create;
inherited Create(true);
FreeOnTerminate := true; // Thread Free Itself when terminated
Suspended := true; // Continue the thread
end;
procedure TuploadTread.Execute;
begin
while not Terminated do
doUpload;//执行查询更新远程数据库的操作.
end;关于调用:
function TFBase.UploadToSc(tableList:TStringList):boolean;
begin
if uploadThread = nil then
begin
uploadThread := TuploadTread.Create(DMData.DatabaseSC,DMData.DatabaseThread,DMData.qySc,DMData.qyLocal);
uploadThread.fTableList := tableList;
uploadThread.Priority := tpLower;//tpIdle;//
uploadThread.OnTerminate:=FreeThread;
uploadThread.Resume;
end;
end;
问题:
1、当主线程调用以后,如果再执行与数据库相关的工作会变的非常的慢。
2、如果网络不通的话,系统就会等待数十秒才会执行。
如何解决这些问题呢?
我只是想在这些传输动作不要影响到主线程的正常工作才加入线程的。
希望有高手能够解决。!
第2个问题,难道你没有PING 吗?
好象上次说过这个问题
其实我有Ping的
假若网络是连通的
如果子线程要处理的数据比较多,
如果子线程没有结束
主线程就会怪怪的。
好像死了一样了。
inherited Create(False);
这样一创建线程就开始工作(执行Execute)
线程的高低才效.要不会占用主线程的(无论你的纯种设置得最低也是).