zoukankan      html  css  js  c++  java
  • 多线程之dispatch_queue_t

    gcd异步多线程操作使用流程,一般在子线程中处理数据,主线程更新界面

    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
                });
            }
        
        });

    今天又张见识了,看下如下的子线程与主线程的调用

     static dispatch_queue_t searchQueue = NULL;
        if( !searchQueue )
            searchQueue = dispatch_queue_create("com.moneytree.searchqueue", NULL);//调度队列
        
    //异步运行 dispatch_async(searchQueue,
    ^{ @autoreleasepool {//ARC模式下自动释放池的写法
    //数据处理放在队列中 NSArray
    *resultData = [[NSArray alloc] initWithArray:[[MTStockManage sharedInstance] stockListMatchingSearchText:searchText fromArray:self.stockList]]; self.stockList = resultData; [self setTableDataSource:nil]; if (resultData.count > SHOW_STOCK_NUMBER) { NSRange range = NSMakeRange(0, SHOW_STOCK_NUMBER); [self setTableDataSource:[resultData subarrayWithRange:range]]; }else { [self setTableDataSource:resultData]; } dispatch_async(dispatch_get_main_queue(), ^{//返回主界面 [self.dataResultTable reloadData]; //主线程中刷新UI }); } });
  • 相关阅读:
    11 数据的增删改
    10 外键的变种 三种关系
    09 完整性约束
    03 body标签中的相关标签
    02 body标签中的相关标签
    01 HTML介绍和head标签
    08 数据类型(2)
    07 数据类型
    06 表的操作
    偶遇RecyclerView内部Bug
  • 原文地址:https://www.cnblogs.com/foxmin/p/2612246.html
Copyright © 2011-2022 走看看