Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Re: Best way to shut down server app

www.cryer.info
Managed Newsgroup Archive

Re: Best way to shut down server app

Subject:Re: Best way to shut down server app
Posted by:"John Carlyle-Clarke" (jpcc@removethis.bigfoot.com)
Date:19 May 2006 11:39:17

Thanks again for the reply, Remy..

"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote in
news:446e068a$1@newsgroups.borland.com:

>
> "John Carlyle-Clarke" <jpcc@removethis.bigfoot.com> wrote in
> message news:Xns97C899A172F89discombobulation@207.105.83.66...
>
>> I'm looking for the best way to close down connections
>> and the application in an orderly way.
>
> Simply deactivate the server via its Active property.  It will
> automatically disconnect any active clients.

This is what I had originally.  I've put it back to this.

>
>> The user closes the form for a connection.  Currently I call:
>>
>> FContext.Connection.IOHandler.Close;
>
> That is not the correct thing to do.  You should be calling
> Disconnect() instead:
>
>     FContext.Connection.Disconnect;
>
> Or
>
>     FContext.Connection.Disconnect(False);
>

This is also what I had originally, so I've put it back to that too.

>
> The Active property already does that for you.  It waits for all
> threads to finish being terminated before it then exits.

Great news.  I added in code to close all connections, then wait for
them all to close, in case that was the problem, but I'll take that out
again.  Taking code out is always satisfying.

>
>> I seem to get some access violations sometimes on shutdown
>> when closing the main form
>
> Your code is likely not thread-safe.  TIdTCPServer is
> multi-threaded, and the VCL (especially GUI components) cannot
> safely be used outside of the main thread.
>

I've made it as thread safe as I know how, but I must have missed
something.  I'm not used to debugging multithreaded code, so I'm
finding it hard going spotting the problem.

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive