ios - 如何取消GCD队列?

标签 ios grand-central-dispatch

我需要知道串行 GCD 队列上尚未启动的任务数。原因是我希望他们“取消”,像这样:

if(!canceled) {
    ... do work
  }

最佳答案

多亏了 Midhun MP 的更换真的很容易:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
// .. some code
    //HERE I need cancel queue, but with GCD it is not possible
    })

所以使用NSOperationQueue的解决方案:

    var oq = NSOperationQueue()
    oq.addOperationWithBlock({
// .. some code
    oq.cancelAllOperations()
    })

关于ios - 如何取消GCD队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28181232/

相关文章:

ios - 当我将一个 View 添加到另一个 View 时(这两个 View 都由 View Controller 控制),我真的应该使用 addChildViewController 吗?

ios - RestKit 0.20 嵌套对象映射问题使用 API

iphone - MPMoviePlayerController 停止 iPod 音乐播放

swift - 使用队列和信号量进行并发和属性包装?

ios - 如何在异步完成 block 内发出同步请求

android - 为什么 Google Flutter 中底部导航栏中的类似项目的文本大小不同?

ios - wifi 连接不良导致 iPad 应用程序崩溃

ios - 在 iOS 上使用 Grand Central Dispatch,如果常规 Objective-C block 不在调度队列中,它们会在哪个队列(如果有)上运行?

ios - Swift 3 DispatchGroup单次成功DispatchWorkItem

swift 3 : Async queue is still blocking main thread/freezing app?