# Foreground and background

- `SETFLAGS $10000` tells the machine to send a "machine switch on" event to the current program, whenever it switches on, even if this program is in the background. If required, use it just once at the start of your program.
- The System OPX procedure `SETFOREGROUND:` brings the current program to the foreground.
- The System OPX procedure `SETBACKGROUND:` sends it to the background again.

Note that each of these should be followed by `gUPDATE` to ensure they take effect immediately.

Note that when a program runs in the background it can stop the "automatic turn off" feature from working. However, as soon as the program waits for a keypress or an event, with `GET`/`GET$` or `GETEVENT32`, auto-turn off can occur.

Auto-turn off can also occur if the program does a `PAUSE` (of 2 or more 20ths of a second), but only if the program has used `SETACTIVE` from `System.opx` to mark the program as inactive. See About OPXs for more on this.