Question

I'm new to GCD, so hopefully I've got the right idea here, but need some advice....

I have an app which needs to do some render processing in the background to maintain performance. So I am using the following code.... ('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 */
    });

Because this is a long running process of several operations, it may be required to restart the render process again by user-interaction on the main thread.

So, how can I signal this process to restart or alternatively form some sort of queue and flag mechanism which can cause this process to abort and allow the rendering to restart.

Help and advice appreciated.

Was it helpful?

Solution

NSOperationQueue is your friend: https://developer.apple.com/library/mac/documentation/cocoa/reference/NSOperationQueue_class/Reference/Reference.html

It has an easier to understand API than GCD but it uses GCD in it's underlying operations. You can reuse, cancel or suspend your background operations easier.

Here is a tutorial on how to use it. http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top