1

I want to stop the execution of the thread.I used "iscancelled" but there is something going wrong..After cancelling the thread it's execution does not stop.

   NSLog(@"YES-------%d,%d", [myThread isExecuting], [myThread isCancelled]);//(OutPut--1,0)
   [myThread cancel];
if([[NSThread currentThread] isCancelled]) 
     {
    [NSThread exit];
 }
   NSLog(@"YES-------%d,%d", [myThread isExecuting], [myThread isCancelled]);//(OutPut--1,1)

How is it possible that after canceling the thread it's execution does not stop????

Thanks,

shashank
  • 123
  • 14
Rohit Singhal
  • 381
  • 1
  • 4
  • 22

2 Answers2

3

I'm pretty certain [myThread cancel] is meant to signal another thread in your program to cancel.

If you want to cancel the current thread, just do [NSThread exit];

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
2

use this in your thread to stop itself -

[NSThread exit];

you can also use cancel method check out this - http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSThread_Class/Reference/Reference.html

Saurabh
  • 22,743
  • 12
  • 84
  • 133