I have created a windows service in delphi. My code is run within ServiceExecute
procedure TMyService.ServiceExecute(Sender: TService);
while not Terminated do
begin
CallSomeProcedure;
Sleep(1000);
ServiceThread.ProcessRequests(false);
end;
end;
Unfortunately, I can not get this code to run. I doesn't seem to call the procedure even when I'm debugging. The code in Myservice.exe looks like this.
begin
if not Application.DelayInitialize or Application.Installing then
Application.Initialize;
Application.CreateForm(TMyService, MyService);
Application.Run;
end.
I can get the serviceExecute to run if I add
MyService.ServiceExecute(nil);
into MyService.exe however if I install it as a service it appears not to be running as Application.Run does nothing
Not sure what I'm doing wrong, but any help would be much appreciated.
Thanks
How to create Windows Service in Delphi? To create a service application in Delphi start Delphi IDE and select File->New->Other. Then select "Service Application". Then you can see application which includes a Datamodule descendent Tservice class.
Applications as a service refers to the delivery of computer software applications as a service via the Internet. This type of software is also referred to as SaaS (Software as a Service), software on demand and on-demand software.
You cannot just run the service from the IDE to debug it; in that case it will just exit. The service has to be started by the service control manager. Also, you shouldn't be calling ServiceExecute directly.
Here's documentation how to debug services.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With