From Xojo Documentation

Revision as of 16:01, 28 January 2019 by PLefebvre (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from ConsoleApplication)

Used to create a Windows service application, which runs in the background without a user interface.

DontDaemonize Resume Stop
Pause Run UnhandledException
BugVersion fa-lock-32.png ExecutableFile fa-lock-32.png RegionCode fa-lock-32.png
BuildDateTime fa-lock-32.png MajorVersion fa-lock-32.png StageCode fa-lock-32.png
Copyright fa-lock-32.png MinorVersion fa-lock-32.png Version fa-lock-32.png
Description fa-lock-32.png NonReleaseVersion fa-lock-32.png
Daemonize DoEvents


A Service application is a special type of ConsoleApplication that is designed to run without any interface and even if are no users logged in. A Service application should not require any user interaction since it's possible that no user is logged in while your application is running. Typical examples of service applications are FTP servers, HTTP servers, and other types of servers that have no user interface.

Console applications rely on the Print and Input commands for communicating with the user. Services behave much the same (depending on how the service is installed, and on what operating system). For example, if your service is run as a daemon on macOS or Linux using the inet.d scripts, then Print and Input will actually correspond to a socket that the system has already attached for you. This means that the Write method of the StandardOutputStream class will actually behave just like a socket and the Read method of the StandardInputStream class will as well.

It is worth noting that this behavior is not guaranteed for all operating systems. If you plan on deploying your service on multiple OS's, it is best to use a TCPSocket directly instead of relying on standard input and output being hooked up to a socket for you.

To create a service application, you must first create a regular console application. Choose File > New Project and choose the Console Application item. A console application has a single project item called App whose super class is ConsoleApplication. Change App's super to ServiceApplication.

The ServiceApplication class is a subclass of ConsoleApplication class, so all the ConsoleApplication events and methods are available. In addition to the ConsoleApplication's events, there are three new events for a ServiceApplication. Some of these events will be fired only on operating systems that support them-and the only OS that supports them currently is Windows.

Installing a Service Application on Windows

If you use an installer, check if it can create the service for you automatically. If you would rather do it by hand, the Windows command sc (service controller) is used to install services.

  sc create RSWebSvc type= own start= auto binpath= c:\Path\To\Exe\WebApp.exe

Do not leave out the spaces after each = sign in the above command.

After the service is installed, you will see it in the Services Manager where you can start, pause or stop it. The following can also be used to start the service:

  sc start RSWebSvc

Note: The sc command should be run with Administrator privileges in order to function correctly.

See Also

ConsoleApplication, StandardInputStream, StandardOutputStream classes; Input, Print, StdErr, StdIn, StdOut methods; TargetConsole constant