Re: NSTimer accuracy
Re: NSTimer accuracy
- Subject: Re: NSTimer accuracy
- From: Cameron Hayne <email@hidden>
- Date: Mon, 18 Nov 2002 19:30:43 -0500
On 18/11/02 12:47 pm, "Mike Laster" <email@hidden> wrote:
>
intermittent bug with a server which needs to run a method every
>
midnight.
>
[...]
>
- (void) timerTick:(NSTimer *)inTimer
>
{
>
NSCalendarDate *alarmTime = nil;
>
NSTimer *timer = nil;
>
>
alarmTime = [[[NSCalendarDate date] beginningOfDay]
>
dateByAddingDays:1];
>
>
[NSThread detachNewThreadSelector:@selector(doDailyStuff:)
>
toTarget:self
>
withObject:nil];
>
>
timer = [NSTimer scheduledTimerWithTimeInterval:[alarmTime
>
timeIntervalSinceNow]
>
target:self selector:_cmd
>
userInfo:[inTimer userInfo]
>
repeats:NO];
>
}
>
[...]
>
alarmTime should be "the next nearest midnight in the future". The
>
problem is that if timerTick: fires at 11:59:59 that means "in one
>
second", which is
>
not my intent.
Why don't you do the following?
Make the timer an instance variable (you will need to 'retain' the pointer)
and use 'initWithFireDate' to set it to fire at midnight the first time and
set it to auto-repeat every 24 hours.
Unless you need it to fore exactly at midnight, that would seem a much
simpler way of doing what you seem to want.
--
Cameron Hayne (email@hidden)
Hayne of Tintagel
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.