« Stop SQL Anywhere when stopping Developer | Main | [Tip] Contextual menus »
February 21, 2007
Running a method every x seconds
If you want to run a method every once in a while you can use Servoy's scheduler plugin. You can quite easily tell the plugin to run method X every minute but in most cases it is smarter to reschedule the method every time: the method might take more than a minute to run for example! So in the method below we run some code and when done we schedule itself again in 20 seconds.
//methodname: mybatchprocessor
//this is where the main code of your method would go.
application.output('running some code');
var startDate = new Date();
startDate.setTime(startDate.getTime()+20000);
//adjust the 20000 above if you need a different interval, it's in milliseconds
var endDate = new Date(startDate.getTime()+10000000);
plugins.scheduler.addJob('in20seconds',startDate,globals.mybatchprocessor,0,0,endDate)
Next set it as your startup method. If you want to run it serverside make it a batchprocessor in the server admin pages. If you make it a batchprocessor don't forget to add some security to your solution to avoid that anybody can launch it!
| Posted by Jan Aleman on February 21, 2007 at 12:11 PM in Tips | Permalink
Comments
Great tip Jan! Thanks.
Posted by: Harjo Kompagnie | Feb 23, 2007 2:36:19 AM