问题
I cannot find any information about it. I have a dispatch_queue_t
in my application where I put some tasks to do. But these tasks take some time and it happens that sometimes they shouldn't be called any more so I would like to clean out queue. Is it possible?
回答1:
Use NSOperationQueue for these capabilities - much more convenient. After adding operations to a queue, you can cancel them and even cancel all pending operations if needed.
Here's a good tutorial to get you started: http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues
回答2:
No, you can't remove items from a dispatch_queue_t. The two options you have are:
- Have you work items check if they've been cancelled before doing their work
- Suspend the queue; this won't remove the items, but it will stop them from running
来源:https://stackoverflow.com/questions/13912001/is-it-possible-to-make-dispatch-queue-t-empty