1

我需要进行验证,为此我需要知道任务是否仍在运行我使用此代码启动任务

    ` SerialQueue = dispatch_queue_create("miColaEnSerie", NULL);
       dispatch_async(SerialQueue, ^{
    [self loadImageFriend:init finalWhitNumber:final img1WithArray:infoImages1 img2WithArray:infoImages2 img3WithArray:infoImages3];
    });`
4

1 回答 1

3

如果您的 SerialQueue 中一次只有一个任务,那么您可以将原子属性添加到类中,例如:

@property (assign) BOOL isSerialQueueRunning;

然后:

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

但是,如果您向 SerialQueue 添加了更多任务,则可以相应地更改BOOL isSerialQueueRunningNSInteger serialQueueTasks增加/减少它。然后验证它是否为 0,这意味着目前队列中没有任何内容。

有时最好实现通知以在任务完成后获取信息并在此之后执行一些操作。

于 2012-10-23T14:58:31.970 回答