?
Solved

Service Application Help

Posted on 2004-04-14
9
Medium Priority
?
351 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 500 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
Technology Partners: 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 500 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

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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

752 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