Solved

Service Application Help

Posted on 2004-04-14
9
349 Views
Last Modified: 2010-04-05
Hey Everyone,

For the last few days I have been trying to port parts of a current application of mine to a service. There are a couple problems:

1) I dont know anything about services (I know what they should do, but dont know how to write em). Added to this, hours of googling turned up nothing relavant.

2)I have got the thing running, and all appearances seem well and good, but no code will execute on startup, and the service terminates itself after about 10 seconds.

Ive chucked the ol ServiceThread.ProcessRequests(False); in the ServiceStart section, but I cant find any good tuts that even explain why this should be done.

Added to this, I am using DBISAM, Windows XP, and Delphi 7. Anything DBISAM related would be really good.

Look forward to the much needed help...
0
Comment
Question by:odders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Accepted Solution

by:
G-Rega earned 125 total points
ID: 10830540
0
 
LVL 3

Author Comment

by:odders
ID: 10830713
Thank G-Rega, but not really what im after. It seemed a little outdated, and had a couple of components that it refernced to that I dont have. And I probably should have specified that im creating a non-interactive service.

Basically what im doing now is creating the service that will act as the database server for the rest of the clients, and admin programs. Extra components im using are Fpiettes Telnet control, DBISAM, and CoolTrayIcons. I know these seem pretty irrelevant, but if anyone knows any consideration that need to be taken into account becuase of these, or has some examples in context, it would be super helpful.
0
 
LVL 3

Expert Comment

by:MarcG
ID: 10831158
"2)I have got the thing running, and all appearances seem well and good, but no code will execute on startup, and the service terminates itself after about 10 seconds.

Ive chucked the ol ServiceThread.ProcessRequests(False); in the ServiceStart section, but I cant find any good tuts that even explain why this should be done."

Did you try someting like:

while True do
begin
  { some code of yours }
  ServiceThread.ProcessRequests(False);
end;

in the OnExecute Event?

When the OnExecute Event is finished the Service Thread is terminated. so to have a service run all the time you need a loop like this.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:odders
ID: 10838225
put that in then, but executing still stops. this is what my onExecute looks like after the additions:

procedure TMaestroService.ServiceExecute(Sender: TService);
var
  iniRead: TIniFile;
  tnetHost, tnetPort: String;
begin
  areaCode := '02';
  readyState := False;
  MessageBoxEx(0, 'Connection Established', 'Confirmation', MB_YESNO or MB_ICONQUESTION or MB_SERVICE_NOTIFICATION, 0);

  iniRead := TIniFile.Create('maestrotel.conf');
  try
    tnetHost := iniRead.ReadString('ServiceSettings', 'IpAddress', '203.17.38.80');
    tnetPort := IntToStr(iniRead.ReadInteger('ServiceSettings', 'PortAddress', 23));
  finally
    iniRead.Free;
  end;

  tnetPrimary.Host := tnetHost;
  tnetPrimary.Port := tnetPort;
  tnetPrimary.Connect;
  InitiateData;

  while True do
    begin
      Sleep(1);
      ServiceThread.ProcessRequests(False);
    end;
end;

Oh, and I forgot one big detail, sorry; the message box ive got in the code doesnt appear, when in onExecute, or onStart. But if manually close the application (form the popup menu on the sys tray), the message box I have there is fired.
0
 
LVL 3

Author Comment

by:odders
ID: 10839454
and the app wont terminate when i call destroy. ive tried calling doDestroy, doShutdown, balh balh, but none work. heres the code behind the click:

procedure TMaestroService.itmExitClick(Sender: TObject);
begin
  if MessageBoxEx(0, 'Are you sure you want to close the MaestroTel Database Service?'#13#13'This may cause any connected client applications to terminate.', 'MaestroTel confirmation', MB_YESNO or MB_ICONQUESTION or MB_SERVICE_NOTIFICATION, 0) = IDYES then
    begin
      sysIcon.HideTaskbarIcon;
      MaestroService.Destroy;
    end;
end;

im upping the points to 250. i just need simple explaination of what importanat commands i need to know when using services, and what considerations i should be taking.
0
 
LVL 12

Assisted Solution

by:Lee_Nover
Lee_Nover earned 125 total points
ID: 10840896
in the OnExecute do a loop checking the Terminated property

while not Terminated do
begin
  // do stuff - if any
  Sleep(1);
  ServiceThread.ProcessRequests(false);
end;

and don't call Destroy ! not for any object .. use Free .. but for services use Terminate - it will set the Terminated property to true and the service thread loop will exit
also restrain yourself from using message boxes in the service
for logging purposes use the service's EventLog, for any user interaction create a separate GUI app which will talk to your service thru let's say TCP/IP (making the gui control internet ready)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 131
Dev Express grid collapse 2 52
how can i search if string exist in array ? 3 75
can i put an image from resource into image tag ? 6 37
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question