• 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
Inactivity Timer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Inactivity Timer


  • Subject: Inactivity Timer
  • From: Kevin <email@hidden>
  • Date: Tue, 24 Nov 2009 16:37:13 -0600

I needed to implement an inactivity timer in my Cocoa App and did so my subclassing NSApplication and overriding sendEvent: to start and stop a timer. Although it works most of the time, every once in a while my timer gets fired as I'm typing text into a text field or interacting with some other control like scrolling a table view.

The relevant code in my NSApplication subclass is shown below. I'd appreciate it if anyone has any insights as to why it isn't working.

#pragma mark -
#pragma mark Inactivity Timer

- (void)sendEvent:(NSEvent *)event
{
    [self stopTimer];

    [super sendEvent:event];

    [self startTimer];
}

- (void)timerExpired:(NSTimer *)timer
{
[[NSApp delegate] performSelector:@selector(timerDidExpire) withObject:nil afterDelay:0.0];
}


- (void)startTimer
{
// Have timer go off in 15 minutes
inactivityTimer = [NSTimer scheduledTimerWithTimeInterval:(15 * 60)
target:self
selector:@selector(timerExpired:)
userInfo:nil
repeats:NO];
[inactivityTimer retain];
}


- (void)stopTimer
{
    if ( inactivityTimer == nil )
        return;

    [inactivityTimer invalidate];
    [inactivityTimer release], inactivityTimer = nil;
}

- Kevin

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Inactivity Timer
      • From: Rob Keniger <email@hidden>
    • Re: Inactivity Timer
      • From: Jerry Krinock <email@hidden>
    • Re: Inactivity Timer
      • From: Dave Keck <email@hidden>
  • Prev by Date: Re: Multiple nibs for this application?
  • Next by Date: Need some pointers for professional printing options
  • Previous by thread: Core Data: Merge Conflicts between *different* objects, other paradoxes
  • Next by thread: Re: Inactivity Timer
  • Index(es):
    • Date
    • Thread