如何在运行mode...when时退出线程我使用NSThread退出我的应用程序被挂起...有人能帮我吗?我可以在这里使用什么来退出线程或关闭线程
谢谢,这是我在这里的第一篇文章。
发布于 2009-05-27 04:22:25
您要查找的例程是return。
当你用来启动线程的函数结束时,线程将终止。您不需要终止NSThread;它会自己处理。您只需从函数调用返回即可。
发布于 2016-06-10 12:10:25
我假设你正在寻找一种方法来取消一个线程,一旦你启动它。一切都在设置中。下面是一个例子:
doCalculation) doCalculation{ /*在此处计算*/ }
- (void) calculationThreadEntry{ NSAutoreleasePool \*pool = [[NSAutoreleasePool alloc] init]; NSUInteger counter = 0; while ([[NSThread currentThread] isCancelled] == NO){ [self doCalculation]; counter++; if (counter >= 1000){ break; } } [pool release]; } application:(UIApplication \*)application
- (BOOL) didFinishLaunchingWithOptions:(NSDictionary _)launchOptions{ /_ Start the thread \*/ [NSThread detachNewThreadSelector:@selector(calculationThreadEntry) toTarget:self withObject:nil]; // Override point for customization after application launch. [self.window makeKeyAndVisible]; return YES; }
在此示例中,循环以线程处于非取消状态为条件。
https://stackoverflow.com/questions/913905
复制相似问题