Multi-thread dispatch_queue_t

Source: Internet
Author: User

Gcd asynchronous multi-thread operation process. Generally, data is processed in sub-threads, and the main thread updates the interface.

static dispatch_queue_t loadDealersQueue = NULL;    if (!loadDealersQueue) {        loadDealersQueue = dispatch_queue_create("com.geelycar.loadactivity.loaddealersqueue", NULL);    }        dispatch_async(loadDealersQueue, ^{        @autoreleasepool {            //Data processing            dispatch_async(dispatch_get_main_queue(), ^{            //Update Interface            });        }        });

Today I have another insight. Let's take a look at the following subthreads and main thread calls:

Static dispatch_queue_t searchQueue = NULL; if (! SearchQueue) searchQueue = dispatch_queue_create ("com. moneytree. searchqueue", NULL); // scheduling queue
// Run dispatch_async asynchronously (searchQueue, ^ {@ autoreleasepool {// write Method for automatically releasing a pool in ARC Mode
// Put data processing in the queue NSArray * resultData = [[NSArray alloc] initWithArray: [[MTStockManage sharedInstance] stockListMatchingSearchText: searchText fromArray: self. stockList]; self. stockList = resultData; [self setTableDataSource: nil]; if (resultData. count> SHOW_STOCK_NUMBER) {nsange range = NSMakeRange (0, SHOW_STOCK_NUMBER); [self setTableDataSource: [resultData subarrayWithRange: range];} else {[self setTableDataSource: resultData];} dispatch_async (dispatch_get_main_queue (), ^ {// return to the main interface [self. dataResultTable reloadData]; // refresh the UI in the main thread });}});

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.