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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:54:52+00:00 2026-06-09T09:54:52+00:00

I have a time consuming process, and have a progress indicator showing the user

  • 0

I have a time consuming process, and have a progress indicator showing the user how far things have gone. Because I have to do the consuming thing ON the main thread, I don’t have the option of simply dispatching an update on the main queue in between updates. I have to switch to a background thread for a moment in order to let the UI update before switching back and continuing.

This is what I have, but it feels very unorthodox. Is there a better way to do “blocks for loops with callbacks to UI” out there that I’m missing? I’m also not entirely sure if this will actually dealloc the block in the end but that’s another story.

__block NSUInteger i = 0;
__block dispatch_block_t obtainBlock;

obtainBlock = [^{
    [self obtainAssetAtIndex:i];
    progressView.progress += progressPerFile;
    i++;
    if (i < assets.count) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
            usleep(500);
            dispatch_async(dispatch_get_main_queue(), obtainBlock);
        });
    } else {
        [self didImportGroup];
        [obtainBlock release];
    }
} copy];

dispatch_async(dispatch_get_main_queue(), obtainBlock);
  • 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-09T09:54:55+00:00Added an answer on June 9, 2026 at 9:54 am

    Way too complicated thinking. Current setup:

    1. do one piece of work
    2. hand control over to background thread
    3. sleep on background
    4. schedule next piece of work on main thread

    What you want to do:

    1. do one piece of work
    2. schedule next piece of work

    Here’s the code:

    - (void)doWork
    {
        if (_assetIndex < assets.count) {
            [self obtainAssetAtIndex:_assetIndex++];
            progressView.progress += progressPerFile;
            [self performSelector:@selector(doWork) withObject:nil afterDelay:0];
        } else {
            [self didImportGroup];
        }
    }
    

    You don’t need a background thread at all (especially when all it’s ever doing is sleeping).

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

Sidebar

Related Questions

In My application have time consuming process.There fore i try to do that operation
I have a time-consuming step to be done, if the user clicks on a
have one time consuming step that flattens a bunch of files. basically i'd like
I have a time-consuming static C# method for creating an array (of double :s)
I have a function a time consuming operation that is done I want to
I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file
I have a Maven project which performs a number of time consuming tests as
I'm currently working on a cross-platform mobile app and have gone through the process
I have an application written in Java that performs some straightforward but time consuming
I am running a time consuming program a lot of times. I have the

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.