Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jun : Re: What is a socket?

www.cryer.info
Managed Newsgroup Archive

Re: What is a socket?

Subject:Re: What is a socket?
Posted by:"Paul" (paul.blommaer..@telenet.be)
Date:Tue, 20 Jun 2006 10:07:11

I've never had no problems with TTimer in services that run 24/7
You just have to create them at runtime.

Paul


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schreef in bericht
news:44971d0d$1@newsgroups.borland.com...
>
> "Richard Bibby" <richardjbibby@hotmail.com> wrote in message
> news:44971bcc@newsgroups.borland.com...
>
>> Why do you not recommend TTimer?
>
> Because TService runs in a worker thread, and TTimer is not thread-safe
> (like most other VCL components in general).  If you place a TTimer on the
> TService at design-time, the TTimer is going to be owned by, and run in
> the
> context of, the main thread.  Any acess to the TService object by the
> TTimer
> OnTimer event handler will not be thread-safe by default, unless you are
> implementing your own thread synchronization code.
>
>> Would it be better to start a thread and use Sleep? The only
>> problem then is I have to handle terminate requests in my thread.
>
> You can have the TService.OnStart event begin the thread, and the
> OnStop/Shutdown events terminate the thread.
>
> Inside the thread itself, just use small Sleeps so that it can check the
> Terminated property in a timely fashion. An alternative approach is to
> have
> the thread create a TEvent object that the TService can signal when it
> wants
> the thread to terminate.  The thread can then wait on the event, with a
> timeout, and terminate itself when the event is signalled.
>
>
> Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive