A SERVICE OF

logo

can be started automatically at system boot time, or can be started manually by using the Services Control
Panel applet. Services are intended to be non-interactive programs that run in the background, and can
even run when no user is logged on to the system. Services generated by Irie Pascal can be run on
Windows NT and Windows 2000. The authoritative source of information about services is the Microsoft
Developers Network (MSDN). You can access the MSDN on the Microsoft website at
msdn.microsoft.com.
Creating WinNT/2000 services
Services must be EXE executables, so in order to create a services you must generate an EXE executable.
See creating EXE executables for more information. In order to generate a service you also need to tell
Irie Pascal to generate a service, this is done by selecting Generate service application in the Code
Generation Project Options. See code generation options for more information.
3.9.3.2 Writing well behaved services
Irie Pascal makes it very easy to create services, see creating services for more information. However
there is one thing you will need to take care. It is up to you to make sure that the services you create stop
promptly when requested to do so. Services are requested to stop when Windows is shutting down, and
when you stop them using the Services Control Applet in the Control Panel. In either case the system will
not wait forever for your service to stop. Well behaved services should not take too long (certainly not
longer than a few seconds) to stop. Irie Pascal supports two built-in functions that you can use to detect
when your service has been request to stop. These two functions are the StopServiceEvent function and
the wait function.
The StopServiceEvent Function
The StopServiceEvent function takes no arguments and returns one of two values depending on whether
your application is a service or not. If your application is not a service then the StopServiceEvent function
will always return zero. If you application is a service then the StopServiceEvent function will return a
handle to the event object that will signal when your service has been requested to stop. See the Irie
Pascal Programmer's Reference Manual (in "progref.html") for more information.
The Wait Function
The wait function takes at least two arguments, the first argument is the maximum length of time the
function should wait (in milliseconds). The other arguments are handles to objects that the wait function
should wait on. The wait function will wait until one of the objects it is waiting on signals it or until the
maximum wait interval expires. The wait function returns the handle to the first object that signals it, or
zero if no object signals it before the maximum wait interval expires. NOTE: If the value of the first
argument to the wait function is zero then the wait function doesn't actually wait instead it just checks
whether any of the objects it is waiting on has signaled it. If the value of the first argument to the
wait function is equal to the built-in contant maxword then the wait function will wait forever for one the
objects it is waiting on to signal it. See the Irie Pascal Programmer's Reference Manual (in
"progref.html") for more information.
Well Behaved Services
Well behaved services will frequently check to see if they have been requested to stop by calling the