書き込み中にアプリがフリーズするため、スレッドにファイルを書き込もうとしましたが、書き込みプロセスを起動するとクラッシュします
2011-10-04 21:53:51.022 xxxxxxxxx[2046:6603] *** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle seekToEndOfFile]: Operation timed out'
私のコード:
- (void)WriteTest{
[NSThread detachNewThreadSelector:@selector(DoWriteTest:) toTarget:self withObject:hFile];
}
- (void)DoWriteTest:(NSFileHandle *)aHandle{
int i;
if (aHandle) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"---start--- writing test file --");
for (i=0; i<1024*1024; i++) {
[aHandle seekToEndOfFile];
[aHandle writeData:[NSData dataWithBytes:bytes length:(sizeof bytes) - 1]];
usleep(1);
}
NSLog(@"---end--- writing test file");
[pool release];
} else {
NSLog(@"ERROR: writing test file thread");
}
}
スレッドなしでこれを行ったとき、このコードは機能します。何が間違っているのか説明してください。Google検索をたくさん行いますが、解決策が見つかりません。ありがとう。