NSTask 还是 NSThread?
我有一些附加到 NSTimer 的代码。它每秒大约 5 次与另一个应用程序交互(通过模拟击键),并在适当的时候发出 NSNotification,由另一段代码处理。
当计时器代码运行时,用户界面没有响应,因此我无法包含停止计时器的“停止”按钮。
我应该如何处理这个问题?一个单独的进程(NSTask 对吗?)还是线程?请记住,在不可预测的时间,计时器代码将需要发回一些信息进行处理。
谢谢。
I have some code that is attached to 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在单独的线程中运行它。它偶尔可以使用
performSelectorOnMainThread:
方法向 UI 报告。Run it in a separate thread. It can report back to the UI occasionally with the
performSelectorOnMainThread:
method.