Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Re: TIdTCPServer shutdown
| Subject: | Re: TIdTCPServer shutdown |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Fri, 14 Sep 2007 00:46:36 |
"Toby Piper" <news@CompCraft.com> wrote in message
news:46ea04fb$1@newsgroups.borland.com...
> I found it. It is the OnDisconnect event handler.
>
> I had a memo that I was writing to in that handler and
> it is hanging there (apparently). I don't know why.
How are you writing to the Memo exactly? Are you accessing it directly (you
shouldn't be) or are you using a synchronization method to access it
indirectly?
Keep in mind that TIdTCPServer is multi-threaded. The OnConnect, OnExecute,
and OnDisconnect events are all triggered in the context of a worker thread,
not in the context of the thread that owns the TIdTCPServer. When you set
the server's Active property to false, the setter method for that property
has to wait for all of the inner threads to terminate before it can exit.
If you do something that blocks that, such as performing a synced operation
in one of the event handlers, and that operation waits on the thread that is
already waiting on the server shutdown (such as when the server resides in
the application's main thread), then you will block the event handler from
exiting, thus blocking the worker thread from terminating, and thus blocking
the server from finishing its shutdown.
If you are using TIdSync or TThread.Synchronize() to access the Memo, and
you don't need to wait for the Memo to update itself before continuing, then
try using asynchrous access, such as the TIdNotify class. That way, no
blockage can occur.
Gambit