Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop current NSOperation?

I'm using NSOperationQueue, and NSOperation for running some function on background click. But I want to be able, when user clicks some button, stop that Operation.

How can I do it?

Something like, [currentoperation stop];
Cancel - won't work me. I want to stop immediately.

Thanks

like image 563
User1234 Avatar asked Oct 19 '11 12:10

User1234


Video Answer


1 Answers

You should be calling the -cancel method, and the operation itself has to support being cancelled by monitoring the isCancelled property/keypath and safely stopping when its value becomes YES. If the NSOperation is your own, you will probably have to create a custom subclass to implement this functionality. You cannot (safely) force an arbitrary operation to immediately stop. It has to support being cancelled.

like image 63
Mike Weller Avatar answered Sep 17 '22 23:09

Mike Weller