ConsoleApplication.Daemonize

From Xojo Documentation

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-damonized 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.

fa-exclamation-circle-32.png
CGI web apps are already daemonized. Do not call this yourself in a CGI web app as it may cause connection issues.

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