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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:59:27+00:00 2026-06-13T11:59:27+00:00

I haven’t used GCD or much threading in my apps but I’ve run into

  • 0

I haven’t used GCD or much threading in my apps but I’ve run into a situation where I need to run a method or two off another thread. Once this method completes I need to call another method using the main thread from a callback. I’ve been searching around to see how to detect when a thread has finished the operation but still not too clear on the subject.

I created a test app and just used the viewDidLoad method for a quick example.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        NSLog(@"viewDidLoad called");
        sleep(5);  // simulating a thread being tied up for 5 seconds


        dispatch_async(dispatch_get_main_queue(), ^{
            [self callbackMethod];  // method called after above thread has completed running
        });

    });


}

Will this example work for what I’m trying to do? When running the application it appears that the callback method is called after the sleep(5) finishes. Is this the proper way of handling this situation or am I way off course?

  • 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-13T11:59:28+00:00Added an answer on June 13, 2026 at 11:59 am

    You’re spot on; that’s the standard pattern for getting off and on the main thread. See my answer here: https://stackoverflow.com/a/13080519/341994

    And for example code from my book, structured in this very way:

    https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch25p868mandelbrotGCD/ch38p1106mandelbrotNoThreading/MyMandelbrotView.swift

    In that example, look at how drawThatPuppy gets off the main thread to do the time-consuming calculations and then back on the main thread to do the drawing into the interface.

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

Sidebar

Related Questions

I haven't used the STL much before, but I started to on this huffman
haven't used regex replaces much and am not sure if how I have done
haven't done much jquery and ran into a problem. I'd like to bind hover
Haven't seen anything about it here but it seems to solve one of the
I haven't used ARC yet other than to deal with it when it forces
I haven't used multithreading in Clojure at all so am unsure where to start.
I haven't actually built an app yet, but I'm confused by documentation on bind-attr.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Haven't done as much of Javascript as I should have done. I am trying
I haven't seen any documentation on them, so they probably don't exist, but it's

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.