Do a thorough job of ensuring that the main process and the PrimaryLoop() thread don't conflict on shutdown.