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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:59:44+00:00 2026-05-15T23:59:44+00:00

How do I cancel a background thread in Objective-C? I am calling background threads

  • 0

How do I cancel a background thread in Objective-C?

I am calling background threads like so:

[self performSelectorInBackground:@selector(setupThumbnails) withObject:nil];

It is called when a swipe happens, for each swipe I want to cancel the previous background thread request.

  • 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-15T23:59:45+00:00Added an answer on May 15, 2026 at 11:59 pm

    Maintain a cancellation property for your thread, and check it periodically within your thread. You’ll need to either use a lock or atomic function (as provided by the operating system and its frameworks, not implemented yourself!) to indicate the thread should be cancelled. The system-provided atomic functions are documented in the atomic manpage.

    Even better would be to use NSOperation on an NSOperationQueue instead of NSThread. It will still perform work in the background using a thread, but it lets the framework and operating system manage a thread pool on your behalf, and NSOperation itself has an isCancelled property you can check – as well as the ability to cancel either an individual NSOperation or all operations in an entire NSOperationQueue.

    For example, you could have a “set up one thumbnail” operation, and then just add one such operation to a queue for each thumbnail to set up. The OS and framework will cooperate to manage the number of threads used to execute those operations, though you could also set the queue’s width to ensure only at most that many imports run at once. And if the user cancels, you can just ask the queue to cancel all the outstanding operations.

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

Sidebar

Related Questions

When I cancel and dispose of my background worker, despite it disappearing from the
Background In my utilities library (Shd.dll) I have a class called AsyncOperation. To put
I call obackgroundworker.CancelAsync(); on a background worker currently doing some work in another thread
All, I have a long running process that I run on a background thread
I want to make a CoreData fetch request on a background thread in order
I am trying to implement search on a background thread using NSOperation on iOS
Lets say I have allocated some memory in my background thread, that is, a
In this question, octy wrote : BTW, if you save on a background thread,
I am using a thread to update messages in background in my application. The
I run a series of time consuming operations on a background worker thread. At

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.