0
我正在每60秒在後臺執行一些任務。後臺任務是服務器從網站請求下載文件。當請求完成時,主線程/ UI似乎被鎖定,我將數據保存到sqlite。NSThread detachNewThreadSelector鎖定主線程
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSThread detachNewThreadSelector:@selector(startTheBackgroundSync) toTarget:self withObject:nil];
[pool release];
- (void)startTheBackgroundSync {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// [self performSelectorInBackground:@selector(moveSynctoBack) withObject:nil];
// [self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
serverSync = [[[ServerSync alloc]init]autorelease];
while (1==1) {
serverSync.delegate = self;
[serverSync syncNow:nil];
[NSThread sleepForTimeInterval:120];
}
[pool release];
[serverSync release];
}
雖然循環不鎖定了主線程,但是當ASIHTtpRequest的數據完成了它鎖定了UI進行了第二次。
是否有可能有ASIHTTPRequest在後臺線程或線程它是從所謂的執行? – iosdevnyc 2011-06-12 17:50:17
@harekam_taj是的,你可以在ASIHTTPRequest子類中覆蓋'threadForRequest'。請參閱源代碼中的註釋('ASIHTTPRequest.m')。注意:這隻適用於高級用戶! – Felix 2011-06-12 18:35:23