0

I am creating new thread on one button click On other button click i want to stop that thread How to implement it...

I have used

[NSThread exit];

but it freezes my UI.....

  • [Here](http://stackoverflow.com/a/3153045/1603234)'s a good answer. – Hemang Oct 22 '12 at 07:44
  • https://developer.apple.com/library/ios/#documentation/cocoa/conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW2 – Omarj Oct 22 '12 at 07:47

1 Answers1

1

use -[NSThread cancel]

- (void)cancel

       Changes the cancelled state of the receiver to indicate that it should exit.

Check the cancellation through -[NSThread isCancelled]

or

exit

Terminates the current thread.

+ (void)exit

This method uses the currentThread class method to access the current thread. Before exiting the thread, this method posts the NSThreadWillExitNotification with the thread being exited to the default notification center. Because notifications are delivered synchronously, all observers of NSThreadWillExitNotification are guaranteed to receive the notification before the thread exits.

Invoking this method should be avoided as it does not give your thread a chance to clean up any resources it allocated during its execution.

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102