2013-03-06 36 views
0

在一個典型的dispatch_async執行:如何檢查dispatch_async隊列狀態?

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ 
    // ... 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     // ... 
    }); 
}); 

要限制僅只有一個塊運行:

if (_loadingFromServer) return; 
_loadingFromServer = YES; 
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ 
    // ... 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     // ... 
     _loadingFromServer = NO; 
    }); 
}); 

有沒有辦法使用以檢查異步模塊運行,沒有_loadingFromServer國旗?

dispatch_queue_set_specific在這種情況下有幫助嗎?

回答