As someone else said I am not too sure what you are trying to do here. But... one method you could employ is to launch your "main" loop as a seperate thread, and have that running on its own. It could then call your sub-function, either in another thread of its own, or within the "main" thread.
The Front panel could then be loaded, and just before you run the user interface, you start your "main" thread. This will then run in the background until terminated eithe by completion of the "main" thread, or when you decided to kill it (not the preferred method). If you want anymore help, let me know and I can send a few examples of starting and controlling threads.
Regards
Chris