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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:32:15+00:00 2026-05-23T02:32:15+00:00

I am working on performing some tasks in the background every 60 seconds. The

  • 0

I am working on performing some tasks in the background every 60 seconds. The background task is the server requests documents to be downloaded form the website. The main thread/UI seems to be locking when the request is done and I am saving the data to sqlite.

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        [NSThread detachNewThreadSelector:@selector(startTheBackgroundSync) toTarget:self withObject:nil];
        [pool release]; 

- (void)startTheBackgroundSync {  

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  

  //  [self performSelectorInBackground:@selector(moveSynctoBack) withObject:nil];  
  //  [self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];  

    serverSync = [[[ServerSync alloc]init]autorelease];
    while (1==1) {
        serverSync.delegate = self;
        [serverSync syncNow:nil];
        [NSThread sleepForTimeInterval:120];
    }
    [pool release];  
    [serverSync release];

}  

While the looping does not lock up the main thread, but when ASIHTtpRequest finished with the data it locks up the ui for a second.

  • 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-23T02:32:15+00:00Added an answer on May 23, 2026 at 2:32 am

    The finished selector of an ASIHTTPRequest will always be performed on the main thread. Therefore you shouldn’t do long running tasks there.

    Instead of launching a new thread you can schedule a repeated NSTimer:

    NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:120 target:self selector:@selector(backgroundSync) userInfo:nil repeats:YES];
    

    … with the following action method:

    -(void) backgroundSync
    {
      ServerSync* serverSync = [[[ServerSync alloc]init]autorelease];
      serverSync.delegate = self;
      [serverSync syncNow:nil];
    }
    

    Be sure that you use the startAsynchronous-method in ServerSync to start the request!

    Furthermore I’d recommend to implement a singleton and then use it like that:

    -(void)init {
       [[ServerSync sharedSync] setDelegate:self];
    }
    
    -(void) backgroundSync
    {
       [[ServerSync sharedSync] syncNow];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with python interactively, it's sometimes necessary to display a result which is some
Working on a project where a sequential set of methods must be run every
I am working on some software that does a sparse matrix-vector multiply. The matrix
I changed some code on an android application that was working perfectly fine at
I am working on a Java application that will use some Hibernate (annotated by
Greetings, I'm working on a JS-based application that does some complex work and logs
I have a website that's working with Facebook Connect (or Facebook for Websites as
I've been spending some of my spare time working a set of collections for
I am working in a desktop application. In my application i am performing login
I'm working on some experiments to try and increase the GPS accuracy on an

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.