既然来了就随便说两句吧!不对别砸我。 先把线程缓存起来。在onterminate事件中。 var cache:TThreadlist; procedure Tmythread.terminate(sender:Tobject); begin cache.add(self); end;程序需要线程时,调用getthread().看看就知道作用。 function getThread:Tthread; begin with cache.locklist do begin if count then begin result:=TThread(items[0]); delete(0); end else result:=TmyThread.create(true); end; cache.unlocklist; end;终止时除掉线程。 procedure ApplicationDeactivate(sender:Tobject); var i:integer; begin with cache.locklist do begin for i:=count-1 do begin item[i].free; delete[i]; end; end; cache.unlocklist; end;ok 了。
多谢勇士出手,不过请问为什么在Tmythread.terminate中将线程加入cache哪?
回复人: happyzsl(学习) ( ) 信誉:100 2002-12-04 15:04:00 得分:0 用Threads来保存线程列表 回复人: aquadp(阿凯) ( ) 信誉:100 2002-12-04 15:05:00 得分:0 好像是用线程的terminate方法和free吧,试试 回复人: happyzsl(学习) ( ) 信誉:100 2002-12-04 15:06:00 得分:0 是TThreadList不是Threads,呵呵 回复人: zhxk32899559(小爪)( ) 信誉:100 2002-12-04 15:22:00得分:0 如何保存啊,能举个例子吗? 回复人: moudy(勇士) ( ) 信誉:100 2002-12-04 16:06:00 得分:0 我的偶像。 回复人: moudy(勇士) ( ) 信誉:100 2002-12-04 16:07:00 得分:0 发错了,sorry。 回复人: happyzsl(学习) ( ) 信誉:100 2002-12-04 16:08:00 得分:0 mylist := TThreadList.Create; mylist.Add(thread1); mylist.Add(thread2); ... 我没实际用过,你试试看,怎样说一下 回复人: moudy(勇士) ( ) 信誉:100 2002-12-04 16:26:00 得分:0 既然来了就随便说两句吧!不对别砸我。 先把线程缓存起来。在onterminate事件中。 var cache:TThreadlist; procedure Tmythread.terminate(sender:Tobject); begin cache.add(self); end; 程序需要线程时,调用getthread().看看就知道作用。 function getThread:Tthread; begin with cache.locklist do begin if count then begin result:=TThread(items[0]); delete(0); end else result:=TmyThread.create(true); end; cache.unlocklist; end; 终止时除掉线程。 procedure ApplicationDeactivate(sender:Tobject); var i:integer; begin with cache.locklist do begin for i:=count-1 do begin item[i].free; delete[i]; end; end; cache.unlocklist; end;ok 了。 回复人: zhxk32899559(小爪) ( ) 信誉:100 2002-12-06 08:47:00 得分:0 多谢勇士出手,不过请问为什么在Tmythread.terminate中将线程加入cache哪? 回复人: zhxk32899559(小爪) ( ) 信誉:100 2002-12-06 08:52:00 得分:0 补充一下,所创建的数目不定的多个线程除非满足一定条件,否则一直在循环执行,并不是一次执行完线程就终止。
mylist.Add(thread1);
mylist.Add(thread2);
...
我没实际用过,你试试看,怎样说一下
先把线程缓存起来。在onterminate事件中。
var cache:TThreadlist;
procedure Tmythread.terminate(sender:Tobject);
begin
cache.add(self);
end;程序需要线程时,调用getthread().看看就知道作用。
function getThread:Tthread;
begin
with cache.locklist do
begin
if count then
begin
result:=TThread(items[0]);
delete(0);
end
else
result:=TmyThread.create(true);
end;
cache.unlocklist;
end;终止时除掉线程。
procedure ApplicationDeactivate(sender:Tobject);
var i:integer;
begin
with cache.locklist do
begin
for i:=count-1 do
begin
item[i].free;
delete[i];
end;
end;
cache.unlocklist;
end;ok 了。
用Threads来保存线程列表
回复人: aquadp(阿凯) ( ) 信誉:100 2002-12-04 15:05:00 得分:0
好像是用线程的terminate方法和free吧,试试
回复人: happyzsl(学习) ( ) 信誉:100 2002-12-04 15:06:00 得分:0
是TThreadList不是Threads,呵呵
回复人: zhxk32899559(小爪)( ) 信誉:100 2002-12-04 15:22:00得分:0
如何保存啊,能举个例子吗?
回复人: moudy(勇士) ( ) 信誉:100 2002-12-04 16:06:00 得分:0
我的偶像。
回复人: moudy(勇士) ( ) 信誉:100 2002-12-04 16:07:00 得分:0
发错了,sorry。
回复人: happyzsl(学习) ( ) 信誉:100 2002-12-04 16:08:00 得分:0
mylist := TThreadList.Create;
mylist.Add(thread1);
mylist.Add(thread2);
...
我没实际用过,你试试看,怎样说一下
回复人: moudy(勇士) ( ) 信誉:100 2002-12-04 16:26:00 得分:0
既然来了就随便说两句吧!不对别砸我。
先把线程缓存起来。在onterminate事件中。
var cache:TThreadlist;
procedure Tmythread.terminate(sender:Tobject);
begin
cache.add(self);
end;
程序需要线程时,调用getthread().看看就知道作用。
function getThread:Tthread;
begin
with cache.locklist do
begin
if count then
begin
result:=TThread(items[0]);
delete(0);
end
else
result:=TmyThread.create(true);
end;
cache.unlocklist;
end;
终止时除掉线程。
procedure ApplicationDeactivate(sender:Tobject);
var i:integer;
begin
with cache.locklist do
begin
for i:=count-1 do
begin
item[i].free;
delete[i];
end;
end;
cache.unlocklist;
end;ok 了。
回复人: zhxk32899559(小爪) ( ) 信誉:100 2002-12-06 08:47:00 得分:0
多谢勇士出手,不过请问为什么在Tmythread.terminate中将线程加入cache哪?
回复人: zhxk32899559(小爪) ( ) 信誉:100 2002-12-06 08:52:00 得分:0
补充一下,所创建的数目不定的多个线程除非满足一定条件,否则一直在循环执行,并不是一次执行完线程就终止。