Article View: borland.public.cppbuilder.nativeapi
Article #14145Re: Programming a TService
From: Remy Lebeau (TeamB)
Date: Fri, 29 Aug 2003 16:37
Date: Fri, 29 Aug 2003 16:37
68 lines
3591 bytes
3591 bytes
"Markus Schadegg" <schadegg@gmx.de> wrote in message
news:3f4f63ab$1@newsgroups.borland.com...
> 1) How can a service terminate itself
> (due to an error, for example)?
A service should not terminate itself. However, if you must terminate the
thread, then you can either:
1) post a SERVICE_CONTROL_STOP message to the service's inherited
Controller() method:
Controller(SERVICE_CONTROL_STOP);
This will still allow the service's OnStop event to be triggered normally.
2) terminate the main ServiceThread itself:
MyService->ServiceThread->Terminate();
This is a brute-force terminatation, and will not allow the service's OnStop
event to be triggered correctly.
> 2) Is a Service always started in the Windows-Directory
> (GetCurrentDir() == "C:\\WINNT\\SYSTEM32", for example)?
No. A service is an executable like any other, it can reside anywhere on
the machine. During installation, it calls the CreateService() function
which sets up the necessary Registry values for the service to work with the
SCM, including the full path to where the service's executable file is
actually located.
> 3) How can I debug a service?
Like you can any other application. The trick, however, is that you have to
start the service normally first, and then use the debugger's "Attach to
Process" feature. You cannot start the service from inside the debugger
directly.
> I have set the Registrykey and I have checked 'Allow Service
> to Interact with Desktop' in the service manager.
That has nothing to do with anything you're asking about.
> 4) What kind of response is the windows service manager waiting for?
> If it does not get such a response, it kills my service...
Yes. It sounds like your service did not response in a timely fashion, so
it was deemed as being locked up and was terminated. Chances are you have
implemented the OnExecute event and are not allowing the service to call its
ProcessRequests() methods correctly. I find that too many people use the
OnExecute event incorrectly. Personally, I like to avoid the OnExecute
event at all costs. Instead, I always start a worker thread in the OnStart
event and stop it in the OnStop/Shutdown events, and leave OnExecute
completely unassigned. TService has more than enough internal behavior to
respond to requests correctly on its own when OnExecute is not used.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03
Technical Details
Message-ID:
<3f4f8148$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f4f63ab$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,dc8a5f42ff15bb2f X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-29 09:39:45 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f4f63ab$1@newsgroups.borland.com> Subject: Re: Programming a TService Date: Fri, 29 Aug 2003 09:37:34 -0700 Lines: 70 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3f4f8148$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1062175048 207.175.226.26 (29 Aug 2003 09:37:28 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail