我有一个带有runLoop内部线程主函数的线程,该函数正常工作。这runLoop是在 while 循环中,如果 cancelled 为 false,它将迭代。
public override func main() {
super.main()
var runLoop: NSRunLoop = NSRunLoop.currentRunLoop()
do {
runLoop.run()
} while(!self.cancelled)
NSLog("Thread stopped")
NSThread.exit()
}
Run Code Online (Sandbox Code Playgroud)
当我为线程设置取消标志(通过NSTreah.cancel()方法)时,线程似乎成功结束,因为我在控制台中停止了线程,但是当我再次尝试启动线程时,我总是得到attempt to start the thread again. 如何重新启动线程而不会出现此错误?
| 归档时间: |
|
| 查看次数: |
2401 次 |
| 最近记录: |