Is it possible to make dispatch_queue_t empty?

守給你的承諾、 提交于 2019-12-24 09:15:13

问题


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:

  1. Have you work items check if they've been cancelled before doing their work
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!