5,388
社区成员
发帖
与我相关
我的任务
分享
uses
contnrs;
var
AList: TObjectList;
AThread: TMyThread;
i: integer;
begin
AList := TObjectList.Create;
try
for i := 0 to 100 do
begin
AThread := TMyThread.Create(False);
ALIst.Add(AThread);
end;
AList.Free; // 此处释放ObjectList,ObjectList会释放里面全部的线程
// 线程被Free的时候,会自动调用WaitFor
// 因此会自动等待全部线程执行完后才继续
except
AList.Free;
raise;
end;
end;