开发者

NSTask or NSThread?

开发者 https://www.devze.com 2022-12-29 09:23 出处:网络
I have some code that is attached 开发者_如何学Goto an NSTimer.Around 5 times every second, it interacts with another application (by emulating keystrokes) and when appropriate spits out an NSNotifica

I have some code that is attached 开发者_如何学Goto an NSTimer. Around 5 times every second, it interacts with another application (by emulating keystrokes) and when appropriate spits out an NSNotification, that is handled by another piece of code.

While the timer code is running, the UI is unresponsive, so I can't include a 'stop' button that halts the timer.

How should I handle this? A separate process (NSTask right?) or thread? Remember that at unpredictable times, the timer code will need to send some info back for processing.

Thanks.


Run it in a separate thread. It can report back to the UI occasionally with the performSelectorOnMainThread: method.

0

精彩评论

暂无评论...
验证码 换一张
取 消