I have an iphone app where on the loading of a view controller, I want to call a web service , get and parse XML all on the background thread. Then update the ui after the thread is done, then fire off another thread to do a secondard operation in another background thread.
Sort of like chaining threading calls:
- UI Thread -> Create BG Thread
- BG Thread -> Call XML service and get results
- UI Thread -> Update UI of the success of the BG Thread operation
- BG Thread -> Fire off part 2 of the operation
All on load of the app.
The issue is that my first, BG Thread operation never seems to end. I added in a waitUntilAllOperationsAreFinished
call after step 2 is done, just to see whats going on and my app never seems to get past that point.
This is sort of the basic skeleton implementation:
- (void) viewDidLoad
{
queue = [[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:1];
//other stuff
[self loadFriendsInBackgroundThread];
}
- (void) loadFriendsInBackgroundThread
{
NSInvocationOperation *operation = [NSInvocationOperation alloc];
operation = [operation initWithTarget:self selector:@selector(invokeLoadingOfFriends:) object: nil];
[queue addOperation:operation];
[operation release];
}
- (void) invokeLoadingOfFriends: (id) obj
{
//webservice calls and results
[self performSelectorOnMainThread:@selector(invokeRefreshAfterLoadingFriends:)
withObject:nil
waitUntilDone:YES];
}
- (void) invokeRefreshAfterLoadingFriends: (id) obj
{
//this line is where is hangs
[queue waitUntilAllOperationsAreFinished];
//never gets here
[self refresh: NO];
}
Any ideas as to why the first thread call never seems to end?
Thanks for any help you can give Mark