Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Apr : Re: How to check for Disconnect on TIdTcpClient

www.cryer.info
Managed Newsgroup Archive

Re: How to check for Disconnect on TIdTcpClient

Subject:Re: How to check for Disconnect on TIdTcpClient
Posted by:"Michael Stieler" (michael.stiel..@rie.eu)
Date:Mon, 2 Apr 2007 14:23:25

Michael Stieler schrieb:
> Hi,
>
>  I have a general question.
>
> I want to receive an event both if a .Disconnect; call succeded and also
> if the connection is closed due to another reason, i.e. an error occured.
>
> Is it right to do it like that?
>
> procedure TModuleProxy.TcpStatus(ASender:TObject; const AStatus :
> TIdStatus; const AStatusText : String);
> begin
>  If AStatus = hsDisconnected then begin
>
>   if readThread<>nil then begin
>     readThread.Terminate;
>     readThread.WaitFor;
>     FreeAndNil(readThread);
>   end;

I found out you must not do this because the OnStatus event can be
triggered by the Read-Thread.
That is a dead-lock because the triggering thread waits for itself to
terminate.

So I have to use a kind of notifying here..

Michael

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive