此代码在工作时按 FIFO 顺序执行两个任务:
-(void) update {
@autoreleasepool {
dispatch_queue_t queue = dispatch_queue_create("us.yellosoft", 0);
// inpternal address
dispatch_async(queue,^(){
// TODO: implement NSProgressIndicator logic
[internalIpMenuItem setTitle: @"Updating..."];
// get IP address from [[NSHost currentHost] addresses]...
NSString *localIP = [self getLocalIP];
// change UI
[internalIpMenuItem setTitle: localIP];
});
// external address
dispatch_async(queue, ^(){
// TODO: implement NSProgressIndicator logic
[externalIpMenuItem setTitle: @"Updating..."];
// get IP address from external JSON service...
NSString *externalIP = [AddressService getIPaddress];
// change UI
[externalIpMenuItem setTitle: localIP];
});
}
}
我想让两个任务同时运行。这可能吗?