ConsoleApplication.Daemonize

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Method

ConsoleApplication.Daemonize() As Boolean

Supported for all project types and targets.

Converts the app from a regular console app to a daemon process that runs in the background on macOS or Linux.

Notes

Since daemonized console apps cannot be run from the IDE, you should build and test as a non-daemonized console app and then daemonize it when you build. Use System.Log to handle debugging.

Although you can also use the Daemonize method on macOS, Apple would rather you use launchd to start daemon processes.

To create a background console application on Windows, you need to use ServiceApplication.

Sample Code

A typical use of the Daemonize method is as follows:

#If Not DebugBuild Then // Do not try to daemonize a debug build
If (args(1) = "start" Or args(1) = "-d") Then // Check for command-line parameter to daemonize
If Not App.Daemonize Then
System.Log(System.LogLevelCritical, "Could not daemonize the app.")
Return -1
End If
End If
#Endif