Reputation: 21
My service does not seem to continuously run.
procedure TService1.ServiceExecute(Sender: TService);
begin
While not Terminated do
ServiceThread.ProcessRequests(True);
end;
This is what I currently have that is suppose to be keeping the service running, but it does not do so.
Upvotes: 0
Views: 689
Reputation: 13
The ServiceThread.ProcessRequests call is needed to allow the service manager requests to be processed (starting/pausing/stopping the service) but you don't call it yourself, nor should you override the TServiceThread instance. The default TServiceThread instance takes care of calling ProcessRequests and also calls the OnStart/OnStop etc handlers of your TService instance.
I normally create a thread in the TService instance OnStart event handler, and let that thread run the service function.
If the service manager stops your service after a short while, it is usually an indication that the ProcessRequests call isn't being called correctly or frequently enough.
Upvotes: 0
Reputation: 36850
This bit of code only runs when the service is started from the Windows Service Manager. Once you have your service .exe
file, use a command prompt to start it with the /install
command line argument, and use net start <your-service-name>
or the Service Management dailog from the Administrative Tools from the Start Menu or Control Panel to start the service.
If you want to run the service in the Delphi debugger, start Delphi with administrative privileges and attach to the running process. But it's more advisable to have all logic in separate units, and have a separate version of the project as a 'plain exe' the run the project's procedures that you can run in the debugger.
Upvotes: 3