【问题标题】:Grand Central Dispatch restart long running process if required如果需要,Grand Central Dispatch 重新启动长时间运行的进程
【发布时间】:2014-05-08 11:37:33
【问题描述】:

我是 GCD 的新手,所以希望我在这里有正确的想法,但需要一些建议......

我有一个应用需要在后台进行一些渲染处理以保持性能。所以我使用下面的代码.... ('ish)

    dispatch_queue_t renderQueue = dispatch_queue_create("myLongRunningProcess", NULL);
    dispatch_async(renderQueue, ^{

    /* Perform several long running rendering processes which could */
    /* take 2-3 seconds in total */
    });

由于这是多个操作的长时间运行过程,可能需要通过主线程上的用户交互再次重新启动渲染过程。

那么,我怎样才能通知这个进程重新启动,或者形成某种队列和标志机制,这会导致这个进程中止并允许重新启动渲染。

感谢您的帮助和建议。

【问题讨论】:

    标签: ios queue grand-central-dispatch long-running-processes


    【解决方案1】:

    NSOperationQueue 是你的朋友:https://developer.apple.com/library/mac/documentation/cocoa/reference/NSOperationQueue_class/Reference/Reference.html

    它的 API 比 GCD 更容易理解,但它在底层操作中使用了 GCD。 您可以更轻松地重复使用、取消或暂停后台操作。

    这是一个关于如何使用它的教程。 http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues

    【讨论】:

      猜你喜欢
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2011-07-28
      • 2023-03-25
      相关资源
      最近更新 更多