Re: NSTimer question: How to fire at second 00, 05, 10 etc ?
Re: NSTimer question: How to fire at second 00, 05, 10 etc ?
- Subject: Re: NSTimer question: How to fire at second 00, 05, 10 etc ?
- From: Chris Kane <email@hidden>
- Date: Wed, 25 Oct 2006 11:30:12 -0700
On Oct 25, 2006, at 8:39 AM, Gilles Celli wrote:
Hi,
I've a question about NSTimer:
I've already set up a Cocoa program to get data from a Multimeter
every 5 seconds but what I really want
is to acquire data at second: 00, 05, 10, 15, 20, etc.
Any ideas ?
Just use one of the variants that takes a start date for the first
firing, and compute the first fire date by taking the current time
interval (since reference date), add small fudge factor (so it's not
"too soon" in the future), round up to the next multiple of 5.0, and
make a date from that. Use that as the first fire date and an
interval of 5.0.
And has anyone any idea about the accuracy (in milliseconds) of
NSTimer ?
Are there any alternatives ?
Well if the program or system is busy doing something else when the
fire date comes around, the firing will be delayed until the timer can
be serviced by the run loop (in the program) and the thread can get
onto a processor. Also keep in mind that the computer's clock is a
simulation of actual time: the computer has to guesstimate how long 5
seconds actually is from its internal interval timers/etc, and outside
forces like NTP can be adjusting the clock to make it change faster or
slower than "normal". For example, the computer can think that 5.0
seconds have passed when only 4.9 seconds (measured by an accurate
outside clock) have passed. Those extra-NSTimer effects could end up
being more interesting.
Otherwise, just write a little test program that just prints the
current time (probably as the reference time interval double, not as a
date object, for more accuracy) in a method fired by an NSTimer, and
see what happens.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden