Quitting NSThread
2 answers
I am assuming that you are looking for a way to cancel the thread as soon as you start it. It's all in customization. Here's an example:
-
(
void) doCalculation {/ * Make your calculation here * /}
- (void) calculateThreadEntry {NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Counter NSUInteger = 0; while ([[NSThread currentThread] isCancelled] == NO) {[self doCalculation]; Counter ++; if (counter> = 1000) {break; }} [release pool]; } application: (UIApplication * application)
- (BOOL) didFinishLaunchingWithOptions: (NSDictionary) launchOptions {/ Start thread * / [NSThread detachNewThreadSelector: @selector (calculate ThreadEntry) toTarget: self withObject: nil]; // Override the point to be configured after starting the application. [self.window makeKeyAndVisible]; return YES; }
In this example, the loop is due to the thread being in a non-canceled state.
0
a source to share