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

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sure. Just instantiate a UIActivityIndicatorView, give it a .frame that… May 16, 2026 at 12:22 pm
  • Editorial Team
    Editorial Team added an answer Make an edit view a user control and have a… May 16, 2026 at 12:22 pm
  • Editorial Team
    Editorial Team added an answer Is silverlight out of the question? http://slfileupload.codeplex.com/ The reason I… May 16, 2026 at 12:22 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I once tried to open a GLUT window from a sub-thread and got lots
To able to do proper cross-thread access I'm using a piece of code something
I am working in an application that is mostly single-thread, single user. There are
I am using vb.net, and in my program I get this 'crossthread operation not
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
I've created a copy utility in c# (.NET 2.0 Framework) that copies files, directories
I have a supposedly single-threaded FLTK application with a popup menu, created with Fluid.
In VIM, I want to execute a command (like :!mkdir src/main/scala/xxx ) Then, I
I'm building a small web application with ASP.NET MVC 2, using db4o as a
How can I unmarshal a message that was marshalled using a QName local part

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.