I implemented the NSTimer like explained in the Shane book:
set theTimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_ selector_userInfo_repeats_(60, me, “timerFired:”, “Whatever”, true)
– do your stuff
– To stop, use the line:
– tell someTimer to invalidate()
I have 3 questions:
Suppose that the timerFired is called every 60 seconds and my stuff take 70 seconds to finish. In this case I would like that the app wait again 60 seconds starting from the end of process. following the example that I have implemented after my stuff finish to process it restart to process again because is invoked every 60 seconds.
In the Shane example the string “Whatewer” is passed as parameter userInfo: How I can get this info (how to pass it) in the timeFired handler?
To update a progress bar that process file I use bindings and property. All works good except that I need to use also the tell contentView to displayIfNeeded() otherwise some properties even if connected with binding are not update regulary.
Actually with NSTimer, you can use the user info. In your example you would access the user info with the statement “someTimer’s userInfo()”.
As for the timing issue, I think you would have to use a non-repeating timer inside the timerFired method. If the work you are doing keeps further lines in that method from running until the work is done, you can just put a non-repeating timer as the last line in that method. It will be automatically invalidated once it fires, and then will be recreated after your work is done each time (you would take out the someTimer invalidate() line).
set theTimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(5, me, “timerFired:”, missing value, false)
– Do Your Stuff
set theTimer to current application’s NSTimer’s scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(120, me, “timerFired:”, missing value, false)
When app is launched the handler is called after 5 seconds for example.
After, the handler process images and when it finish wait 2 minutes (120 seconds) and call again the handler.
The last parameter is set to false.