我正在进行线程处理....我遇到了这个:
-(void)didRecieveResponse:(NSArray*)responseDic{
//Update DB status to '2', which means everything needs to b deleted
[[MediaService sharedInstance] updateMedia:2];
self.projectArray = responseDic;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (int j = 0; j<[self.projectArray count]; j++) {
ProjectJsonModel *pModel = [self.projectArray objectAtIndex:j];
[self parseArray:pModel.imageArray project:pModel ptype:1];
[self parseArray:pModel.pdfArray project:pModel ptype:2];
[self parseArray:pModel.videoArray project:pModel ptype:3];
Media *tmpMedia = [[Media alloc] init];
tmpMedia.projectId = pModel.projetId;
tmpMedia.projectName = pModel.projectName;
// NSLog(@"DB project naem = %@",pModel.projectName);
tmpMedia.fileType = 4;
tmpMedia.fileLink = NULL;
tmpMedia.fileName = NULL;
//NSURL *fileUrl = [NSURL URLWithString:tmpMedia.fileLink];
//tmpMedia.fileName = [fileUrl lastPathComponent];
tmpMedia.status = 4;
[[MediaService sharedInstance] insertMedia:tmpMedia];
[tmpMedia release];
}
[self checkDbForDownload];
dispatch_async(dispatch_get_main_queue(), ^(void) {
//Stop your activity indicator or anything else with the GUI
//Code here is run on the main thread
});
});
将所有在线数据存储到数据库中。它将显示在应用程序中。在检查更新时,应用程序停止工作。
在那个断点没有进入这个循环,为什么?
答案 0 :(得分:0)
dispatch_async
中的代码将异步运行。从外部代码块调试它将作为单行退出整个dispatch_async
,并且不会进入其中的代码块。在for (int j = 0; j<[self.projectArray count]; j++) {
中添加一个额外的断点,而不是从外部块进入以调试代码。这将阻止asyc后台线程在执行时停止。