B
bbcock
Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码创建和释放线程有问题吗?中途关闭程序,线程能安全释放吗?在线程中让主线程的label控件显示信息,需要线程同步吗?
主线程
procedure TForm1.FormShow(Sender: TObject);
begin
thread1:=jieshou.Create ;
thread1.FreeOnTerminate := True;
thread1.resume;
end;
jieshou线程
constructor jieshou.create;
begin
inherited create(TRUE);
end;
procedure jieshou.Execute;
var
j:integer;
begin
if not Terminated then
begin
Hd := FindWindow (nil,'jieshouchengxu');
for j:=0 to 3000do
begin
if terminate then
break;
数据操作代码......
form1.label1.Caption :='正常';
end;
sendMessage(hd,wm_close,0,0);
end;
end;
主线程
procedure TForm1.FormShow(Sender: TObject);
begin
thread1:=jieshou.Create ;
thread1.FreeOnTerminate := True;
thread1.resume;
end;
jieshou线程
constructor jieshou.create;
begin
inherited create(TRUE);
end;
procedure jieshou.Execute;
var
j:integer;
begin
if not Terminated then
begin
Hd := FindWindow (nil,'jieshouchengxu');
for j:=0 to 3000do
begin
if terminate then
break;
数据操作代码......
form1.label1.Caption :='正常';
end;
sendMessage(hd,wm_close,0,0);
end;
end;