How can I Pause a NSOperation in a NSOperationQueue?
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?
- Can AVFoundation be coerced into playing a local .ts file?
- Major Bug, Sprite Atlas created in XCAssets Folder does not support batch rendering
- security / codesign in Sierra: Keychain ignores access control settings and UI-prompts for permission
- Inspecting files of type “NeXT/Apple typedstream” version 4 (NSArchiver)
- Normal casting vs bridge casting in Objective - C
- Is it possible to develop iPhone apps with a Hackintosh?
2 Solutions Collect From Internet About “How can I Pause a NSOperation in a NSOperationQueue?”
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:
- add a
isPausedflag to your
- implement a copy/move method for the operation’s data
- if paused,
setCancelled:(watch for this change in
- create a new operation moving the state from paused operation to new operation
- adjust priority to reorder operation order in queue, if you like
- add the clone to the queue
- return from
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.
- Restoring project after Discarding all changes to Xcode project
- Add “Edit in Excel” or “Edit photo” extension
- “Strip Debug Symbols During Copy” and “Strip Linked Product”
- Animation Stops When Scrolling in UI ScrollView
- Share my iPhone app for testing
- Swift: Pass multiple values between views
- App with jailbreak detection rejected by Apple
- How to store a video/image file from a server in iPhone
- Swift Update Constraint
- Tools for Apache Cordova (VS2015): Adding custom entries to *info.plist for iOS
- Data encapsulation in Swift
- NSUserDefaults Not Saving TextField Text (Swift)
- ARC __bridge cast Block_copy & Block_release
- Compile time key path checking in Swift
- Correct data not showing in ios Charts