C
crasyProg
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用线程向导创建了一个线程类,在线程Destroy时我向主线程postmessage,然后主窗体捕捉到消息后马上再创建一个线程,可是为什么运行一段时间不再创建了呢?源码如下:
线程类代码:
private
myControl:Tcontrol;//控件名称假设的
destruct Mythread.destroy;
begin
postmessage(fom1.handle,wm_threadMsg1,0,0);
inherit;
end;
MyThread.Execute;
begin
try
myControl:=Tcontrol.create(nil);
... //myControl一些属性付值
myControl.timeout=1000;
myControl.do();
myControl.OnSucess=myThreadSucess;
while not terminateddo
application.processmessage;
finally
myControl.free;
end;
end;
procedure MyThread.myThreadSucess(sender:Tobject,..)
begin
postmessage(form1.handle,wm_thredMsg2,1,0);
terminate;//新添代码
end;
主窗体代码:
const
wm_threadMsg1=wm_message+99;
wm_threadMsg2=wm_message+100;
procedure wmthreadmsg(msg:Tmessage):messages wm_threadMsg1;
begin
MyThread.create;
..
application.processmessage;
end;
线程类代码:
private
myControl:Tcontrol;//控件名称假设的
destruct Mythread.destroy;
begin
postmessage(fom1.handle,wm_threadMsg1,0,0);
inherit;
end;
MyThread.Execute;
begin
try
myControl:=Tcontrol.create(nil);
... //myControl一些属性付值
myControl.timeout=1000;
myControl.do();
myControl.OnSucess=myThreadSucess;
while not terminateddo
application.processmessage;
finally
myControl.free;
end;
end;
procedure MyThread.myThreadSucess(sender:Tobject,..)
begin
postmessage(form1.handle,wm_thredMsg2,1,0);
terminate;//新添代码
end;
主窗体代码:
const
wm_threadMsg1=wm_message+99;
wm_threadMsg2=wm_message+100;
procedure wmthreadmsg(msg:Tmessage):messages wm_threadMsg1;
begin
MyThread.create;
..
application.processmessage;
end;