私はiphoneアプリを持っており、View Controllerのロード時に、Webサービスを呼び出し、すべてのバックグラウンドスレッドでXMLを取得して解析したいと考えています。次に、スレッドの完了後にUIを更新し、別のスレッドを起動して、別のバックグラウンドスレッドで2番目の操作を実行します。
スレッド呼び出しを連鎖させるようなものです。
- UIスレッド->BGスレッドの作成
- BGスレッド->XMLサービスを呼び出して結果を取得する
- UIスレッド->BGスレッド操作の成功のUIを更新します
- BGスレッド->操作のパート2を発射します
すべてアプリのロード時に。
問題は、私の最初のBGスレッド操作が決して終了しないように見えることです。手順2が完了した後、何が起こっているかを確認するために電話を追加しましたがwaitUntilAllOperationsAreFinished
、アプリがそのポイントを超えることはありません。
これは一種の基本的なスケルトン実装です。
- (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];
}
最初のスレッド呼び出しが決して終了しないように見える理由についてのアイデアはありますか?
あなたがマークを与えることができるどんな助けにも感謝します