One of the patterns presented at the WWDC 2010 \"Blocks and Grand Central Dispatch\" talk was to use nested dispatch_async calls to perform time consuming tasks on a backgro
This worked for me (added a timer):
[self retain]; // this guarantees that the last release will be on the main threaad
dispatch_async(backgroundQueue, ^{
// do something time consuming in background
NSArray *results = ComputeBigKnarlyThingThatWouldBlockForAWhile();
// use results on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
[myViewController UpdateUiWithResults:results];
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(releaseMe:) userInfo:nil repeats:NO];
});
});
- (void)releaseMe:(NSTimer *)theTimer {
[self release]; // will be on the main thread
}