This method cancels the
timer. If a new
time is set, the
timer is restarted.
var timerObj;
//constructor function for our sample timer listener object
function myTimerCallBack()
{
this.handleMyTimer = handleMyTimerFunc;
}
//timer callback method
function handleMyTimerFunc()
{
alert("This is my timer callback.");
}
//main method
function onInitialized()
{
var objCallback = new myTimerCallBack;
registerMyTimerListener(objCallback, "handleMyTimer");
}
function registerMyTimerListener(myTimerCallback, methodName)
{
timerObj = shell.serviceManager.basics.timer;
var dateObj = new Date();
dateObj.setMinutes(dateObj.getMinutes() + 1);
// register timer callback method to fire after 1 second from the current time
timerObj.setForOffset(myTimerCallback, methodName, 1000);
alert("Cancel timer at this point and reset with new timer");
//cancel before the first timer fires and reset with 3 seconds
timerObj.cancel();
timerObj.setForOffset(myTimerCallback, methodName, 3000);
}