I need to pause a running NSOperation which was inserted in an NSOperationQueue. Currently I am canceling all operations and restarting them. But this would lead to some kind of duplication in terms of process done. I tried with setSuspended flag of NSOperationQueue. But it's not suspending the operation. Is there any way out?
see this: Link
And here from the apple docs:
Suspending and Resuming Queues If you want to issue a temporary halt to the execution of operations, you can suspend the corresponding operation queue using the setSuspended: method.
Suspending a queue does not cause already executing operations to pause in the middle of their tasks. It simply prevents new operations from being scheduled for execution. You might suspend a queue in response to a user request to pause any ongoing work, because the expectation is that the user might eventually want to resume that work.
I've not tried this, but I would probably start here:
isPaused
flag to your NSOperation
subclasssetCancelled:
(watch for this change in -main
)-main
if in -main
note that this will just suspend it. if you really want to pause and explicitly resume, you would manually 'new operation` when you want to resume.
now, if you are observing or have special completions, then you will have a few other problems. for simple cases, it seems this approach would seem to work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With