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;

posted @ 2017-04-14 13:47  delphi中间件  阅读(1017)  评论(0编辑  收藏  举报