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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:35:24+00:00 2026-05-19T12:35:24+00:00

I have recently become thread curious on iOS. Please point me in the direction

  • 0

I have recently become thread curious on iOS. Please point me in the direction you would take, to achieve (if possible) the following on modern iOS devices… thank you!

The user is typing in text, say a word every few seconds.

From time to time I want to launch DifficultProcess to do some semantic processing. In short, I guess I need to be able to do four things:

  • launch DifficultProcess from main
  • if DifficultProcess completes, get a message back from it to the same main
  • abandon, get rid of, DifficultProcess if I want to, from main
  • and finally the priority question: DifficultProcess must have much lower priority than main or user input, I want DifficultProcess to have really really looow priority; is that even possible?

What, essentially, are the calls one uses for A, B, C in modern (2011) (late January) iOS? I don’t care about Dad’s methods! And is “D” even possible in any way?

I guess those are the four ideas!

So in particular I want to send a message to, in other words call a routine in, the running background process (in that way, one could kill off the running background process if desired, or perhaps change it’s mode of operation etc).

(For anyone born before 1997, you will recognise that as a typical “speculative processing” paradigm.)

Thanks for pointers for anyone who can be bothered on this!

  • 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-19T12:35:24+00:00Added an answer on May 19, 2026 at 12:35 pm

    I would recommend using NSOperation and NSOperationQueue to manage background activity that you need to be able to cancel arbitrarily.

    NSOperation’s -cancel and NSOperationQueue’s -cancelAllOperations are the methods to look at.

    To get messages back from the background to the main thread, the dispatch_async-to-main-thread-queue technique is fine. You can combine this with a delegate protocol for your NSOperation to codify the messages you want to send back.

    E.g.

    @protocol MyOperationDelegate
    - (void) operationStarted:(MyOperation *)operation;
    - (void) makingProgressOnItem:(id)anItem otherInterestingItem:(NSDictionary *)otherItem remainingCount:(NSUInteger)count;
    - (void) operationWillFinish:(MyOperation *)operation;
    @end
    
    @interface MyOperation
    id <MyOperationDelegate> delegate;
    @end
    
    @implementation MyOperation
    ...
    
    - (void) cancel
    { 
        [super cancel];
    
        // Tell the delegate we're about to finish (due to cancellation).
        dispatch_sync (dispatch_get_main_queue(), ^{
          [self.delegate operationWillFinish:self];
        });
    }
    
    - (void) main 
    {
        // Check for cancellation
    
        if (self.isCancelled) return;
    
        // Starting
    
        dispatch_sync (dispatch_get_main_queue(), ^{
            [self.delegate operationStarted:self];
        });
    
        if (self.isCancelled) return; // Another cancel check
    
    
        // Send async progress messages periodically while doing some work
    
        while (workNotDone) 
        {
            // Do some work ...
    
            dispatch_async (dispatch_get_main_queue(), ^{
               [self.delegate makingProgressOnItem:foo otherInterestingItem:bar remainingCount:baz];
            });
    
           if (self.isCancelled) return;
        }
    
    
        // About to finish
    
        if (!self.isCancelled) {
            dispatch_sync (dispatch_get_main_queue(), ^{
               [self.delegate operationWillFinish:self];
            });
        }
    }
    @end
    

    KVO is no good for interthread communication; the observation is received on the thread that originates the key value change. So, if your background thread changes a value, your background thread is going to receive the KVO about it. Probably not what you want.

    Grandpa’s -performSelectorOnMainThread:withObject:waitUntilDone: continues to be a fine way to get messages back to the main thread. The limitation is that your messages can only access one object-based argument. The dispatch_async to the main thread doesn’t have this limitation.

    If you want to fire off an asynchronous (or synchronous) NSNotification’s from a background thread to the main thread, you need to use -performSelectorOnMainThread.

    NSNotification *note = [NSNotification notificationWithName:FinishedABunchOfWorkNotification object:self userInfo:nil];
    [[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:note waitUntilDone:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently become aware that our code has several implementations of a version
I have recently become interested in the field(s) of data mining and machine learning.
I have recently become an intern on a startup online classroom system. So now,
While I have written plenty of recursive parsers before, I have recently become interested
Recently I have become a fan of storing various settings used for my testing
Both OOD (Object-Oriented-Design) and MVC (Model-View-Controller) architectures have become staples of modern software design.
I am a novice programmer who mainly uses Java. Recently I have become interested
Recently I have discovered that my release executable (made with msvc++ express 2008) becomes
Have recently been given a project to complete which uses XML quite extensively.Am looking
I have recently started having problems with TortoiseCVS, or more specifically with plink, the

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.