iOS multithreaded-nsoperation

Source: Internet
Author: User

In front of the iOS Nsthread method to implement multi-threading, this is simply about Nsoperation and nsoperationqueue.

Nsoperation is an abstract class that defines a task to perform. Nsoperationqueue is a task queue that helps manage the tasks defined by Nsoperation. When a task is added to the task queue, it automatically runs automatically by priority and dependency.

Nsoperation is not used directly, we must use the inheriting class. iOS provides two well-implemented subclasses, namely Nsinvocationoperation and nsblockoperation. Nsoperation has a Start method that gives you a way to run a task without joining the Nsoperationqueue, which is, of course, a bit higher for developers.

I still use the same function as an example, on the code:

-(void) viewdidload{    [Super Viewdidload];             Object : Image_url];     *queue = [[Nsoperationqueue alloc] init];    [Queue addoperation:operation];}

It looks simple, just create a task and then join the queue. This queue is a task pool that follows the producer-consumer relationship and automatically runs the task when there is a task. We can use Setmaxconcurrentoperationcount: This method to set the total number of threads in this queue, the default value is-1, meaning there is no limit.

iOS multithreaded-nsoperation

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.