문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top