dispatch_queue_t SerialQueue how check if is still running. ios GCD

∥☆過路亽.° 提交于 2019-12-07 16:23:27

If you have only one task at a time in your SerialQueue then you can add atomic property to a class like:

@property (assign) BOOL isSerialQueueRunning;

Then:

 isSerialQueueRunning = YES;
 dispatch_async(SerialQueue, ^{
    [self loadImageFriend:init finalWhitNumber:final img1WithArray:infoImages1 img2WithArray:infoImages2 img3WithArray:infoImages3];
    isSerialQueueRunning= NO;
 });

If however there are more tasks you add to SerialQueue you could change BOOL isSerialQueueRunning to NSInteger serialQueueTasks and increment/decrement it accordingly. Then verify if it's 0 which means nothing is in the queue at the moment.

Sometimes it's better to implement notifications to get information when the task is done and perform some action after that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!