indy9在程序关闭时出现terminate thread timeout的BUG解决办法

时间:2023-03-09 08:52:38
indy9在程序关闭时出现terminate thread timeout的BUG解决办法

indy9在程序关闭时出现terminate thread timeout的BUG解决办法

INDY9线程有BUG,在退出程序的时候会报错:terminate thread timeout(终止线程超时)。

解决办法:

procedure TForm1.DisconnectAll;
var
List: TList;
I: Integer;
begin
List := IdTCPServer1.Threads.LockList;
try
for I := 0 to List.Count - 1 do
begin
try
TIdPeerThread(List.Items[I]).Connection.Disconnect;
except
on E: Exception do
begin
TIdPeerThread(List.Items[I]).Stop;
end;
end;
end;
finally
IdTCPServer1.Threads.UnlockList;
end;
end;

DisconnectAll;  // 先执行
IdTCPServer1.Active := False;