Question

I am trying to get this right, so, the question I have is:

When I instantiate an NSOperationQueue like this:

NSOperationQueue * operationQueue = [[NSOperationQueue alloc] init];

Then add an operation to it:

[operationQueue addOperation:....];

Is the operation NEVER run on the main thread?

What tells me that any operations I add to the queue are run on a background thread 100% of the time and never on the main thread? Is it just the way NSOperationQueues are designed to work?

Thank you

Était-ce utile?

La solution

Correct, operation queues (other than the main operation queue returned by +[NSOperationQueue mainQueue]) are never serviced by the main thread. From the NSOperationQueue class reference:

Operation queues usually provide the threads used to run their operations. In OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central Dispatch) to initiate the execution of their operations. As a result, operations are always executed on a separate thread, regardless of whether they are designated as concurrent or non-concurrent operations.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top