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

  • SEARCH
  • Home
  • 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 3285526
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:16:37+00:00 2026-05-17T20:16:37+00:00

My question is quiet simple (I think). I have a class that implements a

  • 0

My question is quiet simple (I think). I have a class that implements a simple chronometer (using some integers and NSTimer). I would like to close my app (so enter in background mode) but I would like my chronometer still continue to count. How can I manage that ?

Thanks a lot !

  • 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-17T20:16:37+00:00Added an answer on May 17, 2026 at 8:16 pm

    Save the time which was present when you started the timer. Something like self.timerStartDate = [NSDate date];. Calling NSTimer once a second and increment a integer will give you very inaccurate results.
    From the NSTimer Class Reference :

    A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds. If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer. Therefore, the actual time at which the timer fires potentially can be a significant period of time after the scheduled firing time.

    If you use the approach with saving the startTime your Timer even “runs” if the program is not running


    EDIT:
    yes. it is wrong to use a timer to count time.
    I just wrote a little test case. An app with a simple tableview with 12 rows. Two timers, one fired every millisecond, the other is fired every 10 seconds.
    In the first timer I add 1 to an Integer, in the second one I print the result of the first timer and the time which passed since the last time I printed, measured with mach_absolute_time().
    Look at the differences, the first measurements are quite ok, but if I start scrolling in that simple UITableView, which runs in the simulator on my powerful mac you get a big difference.

    2010-10-27 11:16:49.266 MutliTableTest[24726:207] Calculated: 9.988000000000
    2010-10-27 11:16:49.267 MutliTableTest[24726:207] Measured  : 10.000055888000
    2010-10-27 11:16:59.266 MutliTableTest[24726:207] Calculated: 9.986000000000
    2010-10-27 11:16:59.267 MutliTableTest[24726:207] Measured  : 9.999898500000
    2010-10-27 11:17:09.608 MutliTableTest[24726:207] Calculated: 8.091000000000
    2010-10-27 11:17:09.609 MutliTableTest[24726:207] Measured  : 10.341779530000
    2010-10-27 11:17:19.266 MutliTableTest[24726:207] Calculated: 1.966000000000
    2010-10-27 11:17:19.267 MutliTableTest[24726:207] Measured  : 9.658319274000
    2010-10-27 11:17:29.266 MutliTableTest[24726:207] Calculated: 9.991000000000
    2010-10-27 11:17:29.267 MutliTableTest[24726:207] Measured  : 9.999891531000
    

    So don’t use NSTimer, use a NSDate and get the difference between current time and the startTime with something like NSTimeInterval ti = [[NSDate date] timeIntervalSinceDate:self.startDate];

    But I wonder why you need a differenct timeStamp every millisecond

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

Sidebar

Related Questions

First I would like to say that I have only worked with java for
I would like to start my question by stating that this is a C++
My question is quite simple I have a class which contains a (private) object
This is a question I have wondered about for quite some time, yet I
I think this is a moderately neophyte question. I've been using NHibernate/FluentNHibernate for about
I have the following use case: There's a class called Template and with that
Let's say I have a simple class Cat in C#, with a Name property
I have the following JUnit test. The method that I'm testing is quite simple,
In a C#/ASP.NET application, I have a form that renders much like the following
I guess this is a quite simple (read: very simple) question, but I have

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.