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: Gilles Celli <email@hidden>
- Date: Thu, 26 Oct 2006 11:46:52 +0200
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.
Thanks for the reply...but actually (as a newbie Cocoa-programmer) I
tried it but couldn't figure it out (using NSDate ?)...if you have an
example it would be great.
Or what are the advantages to use NSTimer instad of checking the
internal time and launch a requested method (it's what we do actually
with
our C-based UNIX program in the Terminal).
On Oct 25, 2006, at 8:30 PM, Chris Kane wrote:
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