iOS Development multi-thread nsoperation Nsoperationqueue
Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: 16px;">-(void) Viewdidload {</span></p></p><p><p><span style="font-size: 16px;">[super viewdidload];</span></p></p><p><p><span style="font-size: 16px;">/*</span></p></p><p><p><span style="font-size: 16px;">Nsoperation and Nsoperationqueue for multithreaded programming</span></p></p><p><p><span style="font-size: 16px;">Step: encapsulate the action performed into the Nsoperation object</span></p></p><p><p><span style="font-size: 16px;">To add a Nsoperation object to the Nsoperationqueue</span></p></p><p><p><span style="font-size: 16px;">The Nsoperation object is removed from the System.</span></p></p><p><p><span style="font-size: 16px;">Putting encapsulated operations into a new thread execution</span></p></p><p><p><span style="font-size: 16px;">Subclass of Nsoperation:</span></p></p><p><p><span style="font-size: 16px;">Nsinvocationoperation Package InitWithTarget:selector:object:</span></p></p><p><p><span style="font-size: 16px;">Execute-start by default when the main thread is added to the queue only new threads are opened and the default is synchronous execution</span></p></p><p><p><span style="font-size: 16px;">Nsblockoperation Create +blockoperationwithblock:^{}</span></p></p><p><p><span style="font-size: 16px;">Add operation-addexecutionblock:^{}; can be added multiple times as long as the encapsulated operation is greater than 1, the asynchronous</span></p></p><p><p><span style="font-size: 16px;">Execute start</span></p></p><p><p><span style="font-size: 16px;">Child definition Inheritance</span></p></p><p><p><span style="font-size: 16px;">Nsoperationqueue function: start can be executed but synchronous, this is asynchronous, as long as added to automate the operation, automatically open the thread</span></p></p><p><p><span style="font-size: 16px;">Method: 1.addoperation:2.addoperationwithblock:^{}</span></p></p><p><p><span style="font-size: 16px;">*/</span></p></p><p><p><span style="font-size: 16px;">/* concurrency number: number of simultaneous tasks performed</span></p></p><p><p><span style="font-size: 16px;">Correlation method for maximum concurrency (typically 2-3 best):-(nsinteger) maxconcurrentoperationcount</span></p></p><p><p><span style="font-size: 16px;">-(void) setmaxconcurrentoperationcount:</span></p></p><p><p><span style="font-size: 16px;">Cancel the operation of the Queue:-(void) canclealloperation</span></p></p><p><p><span style="font-size: 16px;">-(void) cancle</span></p></p><p><p><span style="font-size: 16px;">Pause and resume: when the thread download interface is turned on, it has an impact on the UI and can be paused when the user slides the interface</span></p></p><p><p><span style="font-size: 16px;">-(void) setsuspended:</span></p></p><p><p><span style="font-size: 16px;">-(BOOL) issuspended Current status</span></p></p><p><p><span style="font-size: 16px;">Operation Priority: Set the priority of Nsoperation in queue</span></p></p><p><p><span style="font-size: 16px;">-(nsoperationqueuepriority) queuepriority;</span></p></p><p><p><span style="font-size: 16px;">-(void) setqueuepriority:</span></p></p><p><p><span style="font-size: 16px;">Operation Dependent: [operationb adddependency:operationa]; action B depends on action a, be sure to set before adding to the queue</span></p></p><p><p><span style="font-size: 16px;">Operational monitoring:-completionblock:</span></p></p><p><p><span style="font-size: 16px;">-setcompletionblock:</span></p></p><p><p><span style="font-size: 16px;">Example: operation.completionblock=^{} This code snippet is executed at the end of the previous task</span></p></p><p><p><span style="font-size: 16px;">*/</span></p></p><p><p><span style="font-size: 16px;">}</span></p></p><p><p>iOS Development multi-thread nsoperation Nsoperationqueue</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service