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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:28:36+00:00 2026-05-18T20:28:36+00:00

I have to perform a timer using a NSThread as I need to download

  • 0

I have to perform a timer using a NSThread as I need to download text data from the web, and without that, in 3G connection it freezes the UI while downloading. So I’ve used a NSThread but it still freezes for a while and I don’t know how to solve this….

Here’s the code I’m using to perform the timer:

- (void)viewDidLoad{
  [NSThread detachNewThreadSelector:@selector(onTimerK2) toTarget:self withObject:nil];
}

- (void)onTimerK2{
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 timer = [NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(onTimerKY2) userInfo:nil repeats:YES];
 [pool release];
}

- (void)onTimerKY2{
    NSLog(@"working");
}
  • 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-18T20:28:36+00:00Added an answer on May 18, 2026 at 8:28 pm

    You’re detaching a new thread to call onTimerK2, which then immediately calls a method back on the main thread, which will of course freeze your interface.

    Edit

    You should be doing any long-running work not on the main thread (either yourself, or by using the asynchronous nature of NSURLConnection as mentioned elsewhere),and then updating your UI by calling selectors on the main thread as this activity progresses.

    Having said that, you may have more success with the following changes/reordering of your code:

    - (void)viewDidLoad {
        timer = [NSTimer scheduledTimerWithTimeInterval:15 
                                                 target:self 
                                               selector:@selector(onTimerK2) 
                                               userInfo:nil 
                                                repeats:YES];
    }
    
    - (void)onTimerK2{
        [NSThread detachNewThreadSelector:@selector(onTimerKY2) 
                                 toTarget:self 
                               withObject:nil];
    }
    
    - (void)onTimerKY2{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSLog(@"working");
        [pool release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses DataTables to perform grouping, filtering and aggregation of
I have a LinkButton that has to postback to perform some logic. Once it
I have a few things that I cannot find a good way to perform
I have a form on an HTML page with multiple submit buttons that perform
I have to perform 3 operations in a windows app as a Transaction. These
I have coded some JavaScript to perform an ajax call in an asp.net application.
I have several customers where my WinForms app does not perform as well as
I have developed a build system on MSBuild (NET 3.0) and cc.net to perform
I have a big red button and I'm trying to use javascript to perform
I have a service written in C# (.NET 1.1) and want it to perform

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.