Reputation: 381
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,
Upvotes: 1
Views: 9705
Reputation: 89509
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];
Upvotes: 3
Reputation: 22873
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
Upvotes: 2