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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:11:23+00:00 2026-05-26T07:11:23+00:00

I have been having some crashes in my app. When checking the logs and

  • 0

I have been having some crashes in my app. When checking the logs and using atos, it is telling me exactly where I get the crash, which is where I tell my NSRunLoop to run:

/**
 * Create a new thread for the timer
 *
 * @version $Revision: 0.1
 */
- (void)createTimerThread {
    NSThread *timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:nil];
    [timerThread start];
    [timerThread release];
}//end


/**
 * Start the actual timer
 *
 * @version $Revision: 0.1
 */
- (void)startTimerThread {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];

    // Start timer
    self.countTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];

    [runLoop run];// <--- Crash happened here
    [pool release];

}//end


/**
 * Update the counter
 *
 * @version $Revision: 0.1
 */
- (void)updateCounter:(NSTimer *)theTimer {

    // Does tons of timer stuff here

}//end

As you can see, the crash happens on [runLoop run] but I have no idea why. It normally happens the second time that I call the createTimerThread method.

What am I doing wrong here? All I was wanting to do was run a timer in the background so that it wasn’t on the main thread because I needed to update a UILabel.

Should I be using something new like Grand Central Dispatch (GCD)?

  • 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-26T07:11:24+00:00Added an answer on May 26, 2026 at 7:11 am

    You said updateCounter is updating a UILabel and that’s being called from the timer that’s running on the background thread. You can’t do that, you need to update UI views on the main thread.

    You can either use performSelectorOnMainThread or GCD (dispatch to the main queue). I compared both using samples on this SO post:

    GCD, Threads, Program Flow and UI Updating

    This SO article specifically has an example of a bg timer with GCD:

    iOS4 Create Background Timer

    Look at the post from mrwalker

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

Sidebar

Related Questions

I have been having some trouble figuring out how exactly I get a process's
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I have been having some problems trying to get my PHP running. When I
Hi, i have been having some problems using JSON data in flash builder lately
I have been having some problems with downward type conversion in C++ using pointers,
I have been having some trouble to select the rows of my table which
I have been having some trouble lately with using custom classes as types. As
We have been having some debate this week at my company as to how
I have been struggling with this for quite some time having been accustomed to
I'm having some trouble with a program using pthreads, where occassional crashes occur, that

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.