Reputation:
hey I have a task in which I need to perform a selector in background thread in which I need to do some video encodeing. The task goes fine. But if I press the back back button then I want that the method should be stop/kill. But it does not stop.
I searched a lot but does not found a satisfactory answere. I tried "cancellAllPreviousRequests" and also looked for NSQueueOperation but could not found how to use it to stop the background selector. Can anybody help me with relevent code.
Thank you in advance.
Upvotes: 0
Views: 292
Reputation: 16134
You need a concurrent NSOperation
which periodically checks if it has been cancelled, via its isCancelled
property. You can then call the cancel
method of the NSOperation
or the cancelAllOperations
of the NSOperationsQueue
to stop the background task. Keep in mind, calling cancel
does not actually stop the operation, but rather sets a boolean property that the operation should be periodically checking to see if it should kill itself (stop doing what it is doing). How often you check for the isCancelled
flag inside your operation code is up to you.
For further reading see here and here.
Upvotes: 1