indy中,IdTcpServer 出现thread terminate timeout 错误的解决办法

引用:

http://delphi.newswhat.com/geoxml/forumhistorythread?groupname=borland.public.delphi.internet.winsock&messageid=3f25c582$1@newsgroups.borland.com

使用indy9.0

在client没有disconnect的时候,设置tcpserver.active:=false 出现”Terminate Thread Timeout.”错误。

另外,虽然主窗体已经消失了,但是,还有程序还是在后台运行,没有退出。

——————————————–

解决办法:

1.IdTCPServer的事件处理中不要有GUI的操作

2.如果AThread.data赋值的是不规范的结构,即不是TObject类型的,需要在disConnect时,
设置Athread.data:=nil;可以在TcpServer的onDisConnect事件中处理。
如果没有设置为nil,在Active:=false时,就会出现timeout了。
> If you do not have an actual TObject assigned to
> the AThead.Data property, and the property is not nil, then you will get a
> crash during shutdown.

3.在TCPServer.Active:=false时,用try..except包围起来,不然还是会出现timeout的exception,不过已经可以退出程序了。

  try
IdTCPServer1.Active := False;
except on e: Exception do
begin
WritetoLog(0, e.Message); end; end;

4.有时候,还是无法正常退出后台程序,那么遍历client的连接,disconnect掉
大部分都是推荐的connection.disconnect,好像是connection.disconnectSocket比较有效。

/////////////
var
List: TList;
I: Integer;
begin
List := IdTCPServer1.Threads.LockList;
try
StatusBar1.Panels[1].Text := ‘Disconnecting…’;
Application.ProcessMessages;
for I := 0 to List.Count – 1 do
begin
try
TIdPeerThread(List.Items[I]).Connection.DisconnectSocect;
except
on E: Exception do
begin
TIdPeerThread(List.Items[I]).Stop;
end;
end;
end;
finally
IdTCPServer1.Threads.UnlockList;
end;

////////////

 

Del.icio.us :
Flickr :
Technorati :

indy中,IdTcpServer 出现thread terminate timeout 错误的解决办法》上有4个想法

  1. 请问你这个自己试验过么,我按照这个做了,始终不好用,依然 出现“terminate thread timeout”错误。
    看见后,请回复一下,谢谢. 急.

  2. 我的版本是9.00.10,自己的代码如下:已经没有timeout的错误出现,你参考一下

    with Server.Threads.LockList do
    try
    for i := 0 to Count – 1 do
    begin TIdPeerThread(Items[i]).connection.disconnect;
    end;
    finally
    Server.Threads.UnlockList;
    end;

    Sleep(Server.TerminateWaitTime);
    Server.Active := False;

回复 abc 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据