Run a Service?
Posted on 2006-04-10
Hi guys, I have an application which I wanted to have the ability to run as a service, I have accomplished this by creating a new Service Application and then adding my units/forms to this app, all works great as a service now, BUT and there is always a but isn't there?? now I would like it to also run as a normal app when double clicked, is it possible to have it both ways? I would hate to have to maintain 2 seperate copies of it, want to be able to run it normally as a windows app, but if people want to use it often and when pc is not logged on then I want them to have the ability also to run /install to install it as service.
I realise I will have to add some intelligence to it so it knows if it is running as a service or not when closing (disable the forms close button as service should be stopped instead etc), current problem is if I run the application (not by starting service) it opens and then closes straight away, I think the service part is causing this as I guess it thinks it has nothing to do :/
I currently have the following in the Services OnExecute event..
while not Terminated do
which seems to keep it alive until stopped when run as a service, why wont this do the same when just run as normal?
Please let me know if you want me to clarify anything, I am sure I am doing something pretty stupid here, not that familiar with Services im afraid.
Thanks in advance!