What’s the most CPU friendly way of waking a Xojo program to do some tasks very infrequenly - eg once an hour, or once a day at 4am in the morning. Is it a thread, or a timer? Or is there some better way. It seems very selfish to have the program sitting there counting the milliseconds 24/7!
I’d use a Timer.
Thanks, Kem. Seems like that’s the definitive answer. My idea is to have a program on a remote server that kicks in occasionally to add files sent in by ftp during the day to a database rather than have the database be sent backwards and forwards all the time. I suppose it might be easier if the users accessed the remote database directly but I don’t think I have the Xojo programming skills to code that just now.
Why use a timer? Just create an executable and schedule a task to run it when you see fit. I don’t know how to do on a Mac but I’ve used task scheduler in Windows a lot.
Well I use a Mac and I have a remote unix server. I have never tried putting a unix build of a Xojo program on the server and I don’t know how I would launch it, so I was thinking in terms of having it launch itself once a day to update the database. I’m starting to look at previous posts about databases but I have only ever tried writing a database program for a standalone Mac and I don’t know if I could cope with extending that to provide access to several users on the remote server just at the moment. I expect my thinking is a bit sloppy at the moment as obviously I’ll need to launch the program at least once. I’m just trying to get the tasks involved clear in my mind.
On a Mac or Linux you can use Cron to schedule execution of a program on interval.
or google ‘mac os x cron’
I’m quite certain you can figure out writing to the database if you have done any programming at all. Most programming languages (including XOJO) make this relatively easy now. I have some trouble myself with the OOP models but the actual process is not hard.
As others have mentioned, CRON is the best way on Linux. For OS X, you can use cron, but launchctl is the preferred method starting with 10.8.
To do this on Linux, Su to root and enter the following sequence:
this will display root’s frontal entries in ‘vi’
add this entry, replacing my var with your app’s path
*/30 * * * * /usr/sbin/MYAPPNAME
This will run your application every 30 minutes as root.
Thanks for all those helpful replies