I attempt to write a file in thread because it freeze my app when writing but when i launch writing process it crash
2011-10-04 21:53:51.022 xxxxxxxxx[2046:6603] *** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle seekToEndOfFile]: Operation timed out'
my code:
- (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");
}
}
when i did this without a thread this code work, can you explain me what i'm wrong please, i make a lot of google search but i don't find a solution. Thanks.