ios - Stop and start NSThread in Swift -
i have thread runloop
inside thread's main function working right. runloop
inside while loop iterate if cancelled false.
public override func main() { super.main() var runloop: nsrunloop = nsrunloop.currentrunloop() { runloop.run() } while(!self.cancelled) nslog("thread stopped") nsthread.exit() }
when set cancel flag thread (through nstreah.cancel()
method), thread appears end, thread stopped in console, when try start thread again getting attempt start thread again
. how can restart thread without getting error?
you cannot restart thread. that's fundamental concept of multithreaded programming, thread runs once , when it's been stopped not restart. create new object instead.
Comments
Post a Comment