【发布时间】:2014-03-26 05:15:08
【问题描述】:
我正在使用 Grand Central Dispatch 在后台运行进程。我想知道如何暂停、恢复和停止该后台线程。我试过了
dispatch_suspend(background_thread);
dispatch_resume(background_thread);
但这些功能对我没有帮助,它继续运行。请有人帮助我。
【问题讨论】:
-
如果实现这种方式比使用 NSOperation 而不是 GCD 更好。使用 NSOperation,您可以更轻松地实现这一点,这也将使您免于许多多线程复杂性和问题。
-
但是为什么上面的GCD功能不起作用?
-
@CRDave,你能给我一个 NSOperationQueue 的例子吗?我试过这个 NSOperation *Queue = [NSOperation new]; NSInvocationOperation *op = [[NSInvocationOperation alloc]initWithTarget:self 选择器:@selector(somefun) object:@"hello"]; [队列添加操作:op];现在我想在单击按钮时暂停操作,现在请告诉我应该使用什么功能来暂停操作
-
那么有没有其他方法可以暂停正在运行的线程呢?
-
或者有什么方法可以停止GCD线程?
标签: ios objective-c grand-central-dispatch