[DUG] basic Service question
Kyley Harris
Kyley at harrissoftware.com
Fri Oct 9 12:08:44 NZDT 2009
Typilcally that happens when your are not running ALL the code in threads,
and are somehow using the main thread to do stuff, which means the messages
from the servicemanager to your app do not get processed and windows thinks
your app is dead.
Also, Make sure in the main program unit that Forms.pas is declared after
SvcMgr.pas
On Fri, Oct 9, 2009 at 12:01 PM, Robert martin <rob at chreos.co.nz> wrote:
> Thanks for the tips :)
>
> This is actually an existing app that I am moving to a service so my
> debugging was really more getting my head around the service stuff. You
> code bel
> ow it pretty much what I am doing except that when I register the app with
> myService.exe /Install Vista comes up with 'myService.exe has stopped
> working ... Windows is checking for a solution to the problem'.
>
> Ta
> Rob
>
>
>
>
>
> Kyley Harris wrote:
>
> With All my services I follow the same thing.. which is
> 1:/ Create a Wrapper object which holds the Guts of the service,
> Including the fact that my service code is always 1 or more Threads that
> instantiate to do work, such as TCP Listening threads etc. The Wrapper
> object is really just a pointer to all the threads.
>
> 2. Create a TService object. and a TForm Object..
>
> 3. in the program file I test a command line switch, and test for /APP
> etc.. and for debugging I run the code as an application from the form with
> a Start And Stop Button.. (no service code for debugging)
>
> 4.. when installing you just run the app with a command line param
> /install or /uninstall you dont need to use the service application.
>
> the TService only ever uses Service Start. and Servicestop
>
> procedure TFITv2Service.ServiceStart(Sender: TService; var Started:
> Boolean);
> begin
> // SvcLog.Service := self;
> Started := True;
> try
> StartServer;
> HssLog('SERVER START IS COMPLETE',hltNormal);
> except
> on E:exception do
> begin
> HssLogExcept(e);
> Started := false;
> end;
>
>
> end;
> end;
>
> procedure TFITv2Service.ServiceStop(Sender: TService; var Stopped:
> Boolean);
> begin
> StopServer;
> // SvcLog.Service := nil;
>
> end;
>
>
>
> On Fri, Oct 9, 2009 at 11:24 AM, Robert martin <rob at chreos.co.nz> wrote:
>
>> Will try that :)
>>
>>
>>
>>
>> Dave O'Brien wrote:
>>
>> Whenever I have tried to create a service I’ve always started with
>> similar problems. I seems to me that you need to use the Start, Stop and
>> Execute methods, and assign Started and Stopped. So maybe move your thread
>> creation code into the Execute method and loop while waiting for it to
>> terminate?
>>
>>
>>
>> *From:* delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz<delphi-bounces at delphi.org.nz>]
>> *On Behalf Of *Robert martin
>> *Sent:* Friday, 9 October 2009 11:00 a.m.
>> *To:* NZ Borland Developers Group - Delphi List
>> *Subject:* Re: [DUG] basic Service question
>>
>>
>>
>> Yeah :)
>>
>>
>> My code isn't using the onExecute I am actually starting and stopping my
>> own Tthread on the onStart event. However The actual (current) problem I am
>> having is that even with no code whatsoever I cant register my service
>> (which I need to do at some point and apparently need for debugging).
>>
>> Cheers
>>
>>
>>
>>
>>
>> Dave O'Brien wrote:
>>
>> Something like this?
>>
>>
>>
>> var
>>
>> Stopped: Boolean = false ;
>>
>>
>>
>> procedure TsvcSomeService.ServiceExecute(Sender: TService);
>>
>> var
>>
>> t: TDateTime ;
>>
>> begin
>>
>> try
>>
>> t := now - 720 ;
>>
>> While (not terminated) and (not stopped) do
>>
>> begin
>>
>> if now > t + (1/1440) then // Run once a minute
>>
>> begin
>>
>> // Do something
>>
>> t := now ;
>>
>> End ;
>>
>> Sleep(1000) ; // Sleep to allow other services time...
>>
>> end ;
>>
>> except
>>
>> end ;
>>
>> end;
>>
>>
>>
>> procedure TsvcSomeService.ServiceStart(Sender: TService;
>>
>> var Started: Boolean);
>>
>> begin
>>
>> Started := True ;
>>
>> Stopped := False ;
>>
>> end;
>>
>>
>>
>> procedure TsvcSomeService.ServiceStop(Sender: TService;
>>
>> var Stopped: Boolean);
>>
>> begin
>>
>> Stopped := True ;
>>
>> end;
>>
>>
>>
>> procedure TsvcSomeService.ServiceCreate(Sender: TObject);
>>
>> begin
>>
>> // Create some stuff
>>
>> end;
>>
>>
>>
>> procedure TsvcSomeService.ServiceShutdown(Sender: TService);
>>
>> begin
>>
>> Stopped := True ;
>>
>> end;
>>
>>
>>
>> -----Original Message-----
>>
>> From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz <delphi-bounces at delphi.org.nz>]
>>
>> On Behalf Of Robert martin
>>
>> Sent: Friday, 9 October 2009 10:34 a.m.
>>
>> To: NZ Borland Developers Group - Delphi List
>>
>> Subject: [DUG] basic Service question
>>
>>
>>
>> Hi
>>
>>
>>
>> I am trying to create a service 9never done this before) and following
>>
>> some old instructions I found on the web. The suggest creating a
>>
>> service then installing it with service.exe /install then adding code
>>
>> and debuggin. I am failing at the most basic point. I am trying to
>>
>> install on Vista from cmd line. It just comes up with a 'program is not
>>
>> responding message.
>>
>>
>>
>> Any help would be appreciated :)
>>
>> Rob
>>
>>
>>
>> _______________________________________________
>>
>> NZ Borland Developers Group - Delphi mailing list
>>
>> Post: delphi at delphi.org.nz
>>
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>>
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
>>
>> unsubscribe
>>
>>
>>
>> No virus found in this incoming message.
>>
>> Checked by AVG - www.avg.com
>>
>> Version: 8.5.421 / Virus Database: 270.14.7/2422 - Release Date:
>>
>> 10/08/09 06:39:00
>>
>>
>>
>> _______________________________________________
>>
>> NZ Borland Developers Group - Delphi mailing list
>>
>> Post: delphi at delphi.org.nz
>>
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>>
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
>>
>>
>>
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com
>> Version: 8.5.421 / Virus Database: 270.14.7/2422 - Release Date: 10/08/09
>> 06:39:00
>>
>> ------------------------------
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
>>
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
>> unsubscribe
>>
>
>
>
> --
> Kyley Harris
> Harris Software
> +64-21-671-821
>
> ------------------------------
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
> unsubscribe
>
--
Kyley Harris
Harris Software
+64-21-671-821
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20091009/b0346c36/attachment.html
More information about the Delphi
mailing list