I’ve spent the last hour or so trying to track down a problem with a multi-threaded GUI Cocoa application that I’ve written.
The problem turned out to be that I was trying to update the applications UI from a background thread. In Cocoa apps, you should only really be updating the applications UI from within the main thread. If you don’t, you get strange results such as the app working in debug and not release or sometimes even hanging altogether.
I fixed the problem by updating the GUI from the background thread by using the performSelectorOnMainThread method. Something similar to below.
-(void)backgroundThread { 
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// .. Update main UI.
[self performSelectorOnMainThread: @selector(updateGui withObject:results waitUntilDone:NO];
// ..
[pool drain];
}
-(void)updateGui:(NSString*) results {
// Update the gui.
}