Steps to use:
(1) Encapsulating the tasks to be performed
(2) Create a queue
(3) Adding operations to the queue
Common methods for Queuing (Nsoperationqueue):
Cancel all operations: [Queue cancelalloperations];
Pause of queue: [Queue Setsuspended:yes]; Users can pause the download operation when they start scrolling
Queue recovery: [Queue Setsuspended:no]; The user starts to download the picture operation when it stops scrolling
Queues can also add actions directly: [Queue addoperationwithblock: ^{}];
Get the home row: [Nsoperationqueue mainqueue];
operation dependent: [Operationa adddependency:operationb];// You can create dependencies between different queue nsoperation, but you can't depend on each other .
Listening operation: Operation.completionblock = ^{};
Nsinvocationoperation is the same point as nsblockoperation:
(1) The no-add operation is not placed in the queue and is performed synchronously in the current thread.
(2) The Start method must be called to execute
(3) If you are adding to a queue, you do not have to call the Start method
Nsinvocationoperation and nsblockoperation different points :
(1) Nsblockoperation not placed in the queue can also be used to thread, using [Blockoperation addexecutionblock:^ (void) block]
Steps and notes for customizing Nsoperation:
(1) must implement the main function, in the main method to achieve the specific operation.
(2) Write a @autoreleasepool method inside the Main method
(3) When comparing time-consuming code, it is necessary to judge (iscancelled) if it has been canceled.
Related knowledge points and points of attention:
(1) nsoperation is an abstract class, does not have the ability to encapsulate operations, must be able to use its subclasses, must implement the Main method
(2) Nsoperation sub-class type: Nsblcokoperation, nsinvocationoperation, Custom (operation)
(3) Maximum number of concurrent Maxconcurrentoperationcount: The maximum number of thread operations opened, generally set to a few;
(4) It is best to determine if it is empty in the Insert dictionary
iOS learning _nsoperationqueue and nsoperation learning notes