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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:42:23+00:00 2026-05-15T13:42:23+00:00

I created a sub-thread using NSThread in main thread NSThread *newThread = [[NSThread alloc]

  • 0

I created a sub-thread using NSThread in main thread

NSThread *newThread = [[NSThread alloc] initWithTarget:self selector:@selector(MyThread:) object:timer];

5 sec later,i used [newThread cancel] in main thread to stop the sub-thread,but it didnt work,

Method MyThread: in newThread still working

so,whats the correct answer to stop newThread,THX

actually [newThread isCancelled] is YES,but selector MyThread was still woking

  • 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-15T13:42:23+00:00Added an answer on May 15, 2026 at 1:42 pm

    The cancel method only informs the thread that it is cancelled (as you mentioned changes the isCancelled to YES. It’s then the responsibility of the thread itself to check this and exit. For example, in your MyThread: method you could do this:

    // At some checkpoint
    if([[NSThread currentThread] isCancelled]) {
        /* do some clean up here */
        [NSThread exit];
    }
    

    You should do this check periodically, and exit from within the thread as shown; otherwise the cancel doesn’t have any effect.

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

Sidebar

Related Questions

The main activity includes some variables with set values. I created a sub-activity with
I want to do following things from main thread/process: Communicate to another process using
when parent thread sleep does sub threads also sleep ? Now main thread is
I have created a sub-domain forum.new4u.com for the site new4u.com . Actually the forum
I created a SharePoint sub-site, and accidently deleted all permissions groups except for the
I created a custom menu called sub-top-nav and now I'd like to override the
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
I want to create sub-domains using PHP on the fly. Suppose a user registers
I created a server-client application using the asynchronous socket. I found the problem when
I am thinking about using a WebBrowser object to create a screen shot of

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.