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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:02:04+00:00 2026-05-14T21:02:04+00:00

i want to block the main thread until something else is done in the

  • 0

i want to block the main thread until something else is done in the background.

i used:

result=[self performSelectorInBackground:@selector(calculate:) withObject:expression];

just bellow this line I am using result:

[self use:result];

i dont want to use result until it is available.
to achieve this I implemented

-calculate:
{
    [[(AppDelegate *)[[UIApplication sharedApplication] delegate] queue] waitUntilAllOperationsAreFinished];
    calculating result...
}

and still, the result is used before it is calculated. so, i didnt block the main thread. pls help me do that.

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-05-14T21:02:04+00:00Added an answer on May 14, 2026 at 9:02 pm

    You don’t want to block the main thread; it will prevent users from using the UI.

    What you want is to use the result obtained in the background once it’s ready.

    One method is to call -use: at the end of the method called in the background: you define

    -(void)calculate:(NSString*)input 
    {
        .... do the calculation ...
        [self performSelectorOnMainThread:@selector(use:) withObject:result];
    }
    

    then you just call from the main thread

    [self performSelectorInBackground:@selector(calculate:) withObject:expression];
    

    This way, you can achieve what you want without blocking the main thread.

    By the way, -performSelectorInBackgronud has nothing to do with NSOperationQueue. So [queue waitUntilAllOperationsAreFinished] doesn’t wait the execution of the method invoked by -performSelectorInBackground.
    And in any case, you shoudln’t call waitUntilAllOperationAreFinished unless absolutely necessary.

    To know when an NSOperation is done, you KVC the property isFinished. See the NSOperation reference.

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

Sidebar

Related Questions

I want to otherwise block code execution on the main thread while still allowing
It seems that finally block doesn't execute if it other than main thread execute
I want to block a specific phone number that is in my database I
I want to block an entire ip range from my webserver but I'm not
I want to block non-browser clients from accessing certain pages / successfully making a
I want to block special character in this code. In other words, user can
I want to block few mobile numbers from my application. I mean can receive
I want to block scrolling page out of the iPhone screen (when gray Safari's
I want to block all incoming connections with iptables on my android device. I
I have created a simple web browser using c# and I want to block

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.