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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:53:40+00:00 2026-05-23T12:53:40+00:00

I am trying to resolve UI issues surrounding NSTimer/NSOperationQueue performing inconsistently. I am seeing

  • 0

I am trying to resolve UI issues surrounding NSTimer/NSOperationQueue performing inconsistently. I am seeing that regardless of whether I use NSTimer or NSInvocationOperation to trigger the code below, many times the performance is as needed, but several times the behaviour is slow (and as in the example below, the code runs for well over 1 sec sometimes).

Here is my code as invoked via NSInvocationOperation:

-(void) progressAsynch{
    for (count = 1; count<=100; count++) {

        // Reposition Label's CGRect.
        [self performSelectorOnMainThread:@selector(moveLabelToNewPosition) withObject:nil waitUntilDone:YES];

        //Update the progress of the progress view
        [self performSelectorOnMainThread:@selector(advanceProgressViewProgress) withObject:nil waitUntilDone:YES];

        //Sleep for 10 millisecs
        [NSThread sleepForTimeInterval:0.01];

        //if the progress view has progressed fully call main thread to to next tasks.
        if(progressView.progress == 1) {
            [self performSelectorOnMainThread:@selector(processResult) withObject:nil waitUntilDone:YES];
        }
    }

}

The code of the method invoked by the NSTimer( triggering every 10 ms) is very similar to the above, just that it would not have the for loop in it.

Evidently, it appears that there is something outside of this processing that is slowing this performance every so often.

Curious to know if you’ve into similar issues, or if you have any pointers/tidbits that might help me out.

Thanks in advance..

  • 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-23T12:53:41+00:00Added an answer on May 23, 2026 at 12:53 pm

    Inter-thread communication is not that fast, and waitUntilDone:YES adds additional thread-synchronization overheads and is completely unnecessary (I’m pretty sure performSelectors are serialized). You might have better luck doing something like

    -(void) progressAsynch{
        for (count = 1; count<=100; count++) {
            [self performSelectorOnMainThread:@selector(stuff) withObject:nil waitUntilDone:NO];
            [NSThread sleepForTimeInterval:0.01];
        }
    }
    

    However, this is still bad. It looks like self is a view or view controller which will be retained by the NSInvocation, and presumably released on the background thread. Most of UIKit is not thread-safe; the Game Center example code goes to great lengths to state that UIKit classes should not even be released on background threads, because the release might cause a -dealloc, which in UIKit classes might not be thread-safe. (Ouch.)

    (Also note that your call to progressView.progress is not safe from a background thread.)

    You’re also at the limit of what’s possible: I’m pretty sure that iOS timeslicing is 10 ms, which means that if anything else needs the CPU at any point (and there are a lot of background processes; try using Activity Monitor in Instruments sometime) your animation might appear to lag.

    Finally, with some audio-playing code, we’ve noticed that NSTimer is not very accurate. I’m not sure why. I think we fixed it with something that used SIGALRM (and code which probably wasn’t signal-safe, sigh).

    You might have better luck with CADisplayLink, which is synced with the refresh rate of the display (I think you pass it [UIScreen mainScreen]) and designed to be used by animations, so it should perform a bit better. iOS 3.1+, but I suspect there’s little point supporting 3.0.

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

Sidebar

Related Questions

I am trying to find a solution that will resolve a recurring deadlock situation
I'm trying to consume a webmethod but it seems that my application can't resolve
I am trying to resolve some fxcop issues and I am really confused about
I'm trying to debug and resolve some issues with a Win32 macro application written
I'm trying to resolve a few issues from infiniteCarousel . It's great because it's
I am trying to resolve a problem with a set of packages that apparently
Hello I've been trying to resolve the issue that I've been having with the
Ok so I've spent a couple hours trying to resolve this issue and have
I am going nuts here trying to resolve a cascading update/delete issue :-) I
In my efforts to resolve Python issue 1578269 , I've been working on trying

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.