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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:34:05+00:00 2026-06-09T04:34:05+00:00

I have a synchronisation process which sometimes (even rarely) takes 20 seconds. I used

  • 0

I have a synchronisation process which sometimes (even rarely) takes 20 seconds. I used to call the selector in the background. There is a progress indicator which stops animating on a notification that the sync is finished, and with the code below it changes straight away:

[self performSelectorInBackground:@selector(updateFunction) withObject:nil];

But in order to allow the progress to continue I decided to use the background task:

    UIApplication *application = [UIApplication sharedApplication]; //Get the shared application instance

    __block UIBackgroundTaskIdentifier background_task; //Create a task object

    background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {
        [application endBackgroundTask: background_task]; //Tell the system that we are done with the tasks
        background_task = UIBackgroundTaskInvalid; //Set the task to be invalid

        //System will be shutting down the app at any point in time now
    }];

    //Background tasks require you to use asyncrous tasks

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //Perform your tasks that your application requires

        NSLog(@"\n\nRunning in the background!\n\n");
        [self updateFunction];

        [application endBackgroundTask: background_task]; //End the task so the system knows that you are done with what you need to perform
        background_task = UIBackgroundTaskInvalid; //Invalidate the background_task
        NSLog(@"Finished in the background!");
    });

But now, when the task is finished the notifications is sent (and executed) but the cell in the table doesn’t update until (sometimes) a significant amount of time. So it seems to me that the ‘needs display’ is not triggered when coming from a background task or so, and is only updated at a regular refresh interval or so.

Is there a way to have the table cell update using background tasks, or am I missing something?

Edit:
The notification listener is:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(refreshBttn)
                                             name:@"finishedUpdate"
                                           object:nil]; 

The code is:

- (void) refreshBttn {
    NSLog(@"Refresh Buttun action");
    iDomsAppDelegate *delegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];
    if([delegate updating]){
        [_updateBttn setHidden:TRUE];
        [_activityIndicator startAnimating];         
    } else {
        [_updateBttn setHidden:FALSE];
        [_activityIndicator stopAnimating];        
    }
    [self setNeedsDisplay];
    [self setNeedsLayout];
}
  • 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-09T04:34:06+00:00Added an answer on June 9, 2026 at 4:34 am

    You need to split up your logic between background and foreground threads. The notification you’re sending should be sent from the main thread, so that your UI objects listening to it can update themselves safely. So, break up updateFunction into two pieces. Perhaps something like this:

    NSLog(@"\n\nRunning in the background!\n\n");
    [self updateFunctionBackground];
    dispatch_async(dispatch_get_main_queue(), ^{
        // send your notification here instead of in updateFunction
        [[NSNotificationCenter defaultCenter] post...];
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database-synchronisation task that takes some time to process, as there are
I have two processes which I am to synchronize. Process A is running as
I have an application which runs some multi-threading process. In each thread I'm sharing
Background: I haven't had much experience with multi-process Perl scripts. I have a data
just wondering what tips people have for avoiding game synchronisation issues in multiplayer games
I have a multithreaded program which uses pthread mutexes for synchronization on few integers.
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
I have a taskBarIcon element extending Application Context from which my entire UI is

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.