I want to create a background thread on the iPhone that executes some code every 10msec. But before I get lost in the concurrency programming guide and the threading program
It is pretty simple and clean if you do it with NSThread. With no need to subclass it.
- (void)backgroundStuff {
while (!self.cancelThread) {
// do your work
[NSThread sleepForTimeInterval:0.01];
}
}
Just an ordinary function. cancelThread is a member variable you declare. Start it with
[NSThread detachNewThreadSelector:@selector(backgroundStuff) toTarget:self withObject:nil];
and you can cancle the thread anytime with self.cancelThread = true;