Cocoa - NSThread 和急救人员
当我启动第二个后台线程并暂停主线程时,我的第一响应者是否仍在运行?例如,我有一个名为 -flagsChanged 的覆盖方法,并且想知道如果主线程离线,它是否仍然处于活动状态。
谢谢,
凯文
When I start a 2nd background thread and pause the main thread, will my First Responder still be in action? For example I have an overwriting method called -flagsChanged and was wondering if it would still be active if the main thread is offline.
Thanks,
Kevin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要暂停主线程,因为主线程线程负责处理事件,并且您的应用程序 UI 将变得无响应。如果主线程暂停,它将不会处理事件,因此它不会将关键事件分派给第一响应者。
如果您认为需要暂停主线程,则可能需要重新设计程序,以便将需要睡眠的行为(如果确实需要睡眠)偏移到辅助线程。如果您需要从辅助线程更新用户界面,则应使用 -performSelectorOnMainThread:withObject:waitUntilDone:。
Don’t pause the main thread since the main thread is responsible for handling events and your application UI will become irresponsive. If the main thread is paused, it won’t handle events, hence it won’t dispatch key events to the first responder.
If you think you need to pause the main thread, you probably need to redesign your program so that the behaviour that requires sleeping (if it does require sleeping) is offset to a secondary thread. If you need to update the user interface from a secondary thread, you should use
-performSelectorOnMainThread:withObject:waitUntilDone:
.