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 8846765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:05:11+00:00 2026-06-14T12:05:11+00:00

I have a problem with NSTimer. I start and repeat it every 100ms and

  • 0

I have a problem with NSTimer. I start and repeat it every 100ms and I have a counter to check if i runed 10s. The problem is it stoped in near 1 minute, not in 10s.
Here is my code

timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkTimer) userInfo:nil repeats:YES];

-(void)checkTimer
{

    timerCount += 1;

        if(timerCount == 1)
        {
                NSLog(@"start");
        }

        if(timerCount == 103)
        {
            NSLog(@"i got it");
        }
}

here is the log:

2012-11-19 08:57:42.063 Karagram[11708:540b] start
[Switching to process 8707 thread 0x2203]
2012-11-19 08:58:39.514 Karagram[11708:540b] i got it

I don’t understand why it wrong. Somebody can tell me why?
Thanks.

  • 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-06-14T12:05:12+00:00Added an answer on June 14, 2026 at 12:05 pm

    NSTimers aren’t guaranteed to be accurate to within more than 100 ms or so. The NSTimer documentation says:

    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.

    By having it fire every 100ms you’re compounding the error, because if it’s off 50 ms every 100ms, by the time 10s has passed it could be quite far from what you expect.

    If you’re wanting to take some action after 10s, why not just set the timer to fire after 10s?

    NSLog( @"start" );
    timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(checkTimer) userInfo:nil repeats:YES];
    
    -(void)checkTimer
    {
        NSLog(@"i got it");
    }
    

    Also, are you doing your streaming on the main thread? NSTimers work on the main runloop, so if you’re blocking the main thread, timers aren’t going to fire until it’s unblocked.

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

Sidebar

Related Questions

I have a problem when creating an NSTimer without repeat. Imagine I create a
I have problem with show or hide form in Window Form Application. I start
I have problem SIMILAR to preventing form data reposting, but not quite the same
so here is the problem i have, i created two NSTimer objects and they
I have a problem with the animation. At start, everything is smooth. However, when
I have little problem in my iPhone application code but can not identify. please
I have a state-transition problem with NSTimer, of which I find difficult to keep
I have a small problem i'm using this code to start counting from 20
I have a weird problem invalidating NSTimer. As long as the user is on
I have got a strange and rare problem here. I am using NSTimer event

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.