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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:12:05+00:00 2026-05-27T22:12:05+00:00

I want to create a background thread on the iPhone that executes some code

  • 0

I want to create a background thread on the iPhone that executes some code every 10msec.
But before I get lost in the concurrency programming guide and the threading programming guide of apple again, I wanted to ask whether someone here can help me out.
What I want to do:

  • Create a background worker thread
  • Trigger the execution of a method every 10msec. (probably by using a NSTimer in that thread?)
  • Put as less load on the main application thread as possible

In my understanding subclassing NSThread and writing my own main method in that subclass should do the trick. That way I don’t use an NSTimer for the update intervals but something like:

[NSThread sleepForTimeInterval: 0.01];

Also queuing mechanisms between main thread and worker thread don’t make any sense, as the worker thread should perform the same operation over and over – until stopped.

The question is: How can I configure the thread to use a timer? I can’t see how I can attach a NSTimer to that worker threads Run Loop?

  • 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-27T22:12:05+00:00Added an answer on May 27, 2026 at 10:12 pm

    It’s possible to do this using the method you outline, but have you looked at using Grand Central Dispatch? It can make some of this a lot easier:

    dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(backgroundQueue, ^{
        while ([self shouldKeepProcessingInBackground]) {
            [self doBackgroundWork];
            usleep(1e4);
        }
    })
    

    You can also use a timer dispatch source to do work periodically:

    dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t timerSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, backgroundQueue);
    dispatch_source_set_timer(timerSource, dispatch_time(DISPATCH_TIME_NOW, 0), 0.01*NSEC_PER_SEC, 0*NSEC_PER_SEC);
    dispatch_source_set_event_handler(timerSource, ^{
        [self doBackgroundWork];
    });
    dispatch_resume(timerSource);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a background thread that's owned by an object. When that
I want to create a background Thread handling some tasks (Runnable) and executing them
I want to create some up and down buttons using the standard button background
I want to create a separate thread from main thread and do some processes
I'm in a static class in a background thread , but i want to
Background : I want to create a custom VB compiler, extending the original compiler,
I want to create a function that performs a function passed by parameter on
In Android, if I want to do some background work, what is the difference
i'm creating asmx web service and have to create thread to do background IO
I've got a background worker and I'm trying to get it to create 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.