• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimer accuracy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >NSTimer accuracy (From: Mike Laster <email@hidden>)

  • Prev by Date: [OT] Re: Table View Blues
  • Next by Date: Network information
  • Previous by thread: NSTimer accuracy
  • Next by thread: Realities
  • Index(es):
    • Date
    • Thread