An alternative approach that might serve you just as well is to make your program run all the time but set the priority to "Idle". This way it stays running in the background whenever there are spare CPU cycles meaning you never have to exit. I've seen some benchmarks done on Folding@Home which uses this approach and the impact of the client on system performance is negligable.
I'm guessing this throws all hope of cross platform compatability out the (heh) window but it didn't seem to be an important consideration...
--
Grant me the wisdom to shut my mouth when I don't know what I'm talking about.