Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 214437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:22:28+00:00 2026-05-11T18:22:28+00:00

I have an NSTimer running in my application that collects some data and sends

  • 0

I have an NSTimer running in my application that collects some data and sends it to a server periodically. In production the timer will fire every few hours.

I am worried about interfering with automatic sleep. In testing, some combinations of timer and sleep time prevent automatic sleep entirely — the display sleeps, the system keeps running. Setting my NSTimer to one minute always stops it.

Some Mac applications are notorious for interfering with automatic sleep when running (or all the time, if they install a daemon). What actions stop the system from sleeping and how can I run periodic tasks safely?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:22:28+00:00Added an answer on May 11, 2026 at 6:22 pm

    Accessing the disk will prevent your computer from sleeping, according to Apple’s article “Mac OS X: Why your Mac might not sleep or stay in sleep mode“.

    Additionally, my testing has shown that the priority of a thread also has an impact on whether or not a computer will sleep. The following code with a timer will allow a computer to sleep.

    @implementation AppController
    
    -(void)timerFired:(NSTimer *)aTimer
    {
    
    }
    
    -(void)spawnThread
    {
       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       [NSThread setThreadPriority:0.0];
    
       [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
    
       while(1) //Run forever!
       {
          [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:300]];
       }
    
       [pool drain];
    }
    
    -(void)awakeFromNib
    {
       [NSThread detachNewThreadSelector:@selector(spawnThread) toTarget:self withObject:nil];
    }
    
    @end
    

    Removal of the setThreadPriority call will prevent the computer from sleeping.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that is attached to an NSTimer. Around 5 times every
i have this timer [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimerFunc) userInfo:nil repeats:YES]; and on some function
I have an app in which i download some data periodically (i currently use
I have created an app that uses NSTimer, which gets triggered each second. My
I need to start NSTimer by 0:0:0 that I am doing and I have
I have an NSTIMER that counts the time, and on t = 10, it
I have an NSTimer that runs at 60hz. With an OpenGL scene loaded and
I have an NSTimer object that I need to repeatedly execute. The code that
If I have an NSTimer that starts in viewdidload, where is the proper place
I have a timer that I use to check a web address every 11

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.