当模式对话框打开时如何接收通知
我需要向 GUI 线程发送消息,该消息应在 GUI 线程下次空闲时进行处理。该消息可以来自 GUI 线程或后台线程。
我尝试了 MachPort/通知的组合。但是,当我执行“
[[NSNotificationQueue defaultQueue] enqueueNotification: my_notify postingStyle: NSPostASAP];
如果存在模式对话框,则不会分派”时,我必须在处理对话框之前关闭对话框,因此这对我来说不可用。
在菜单选择或实时调整大小期间不处理消息是可以的,但模式对话框的延迟有点太多。
I need to send messages to the GUI thread which should be processed the next time the GUI thread is idle. This message can come from the GUI thread or background threads.
I tried a combination of a MachPort/Notification. But when i do a
[[NSNotificationQueue defaultQueue] enqueueNotification: my_notify postingStyle: NSPostASAP];
This is not dispatched if there is a modal dialog, i have to close the dialog before it is processed so this is not useable for me.
It's okay to not handle messages during menu selection or live resize, but modal dialogs is a little bit too much delay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答:不要使用模式对话框。
长答案:模态对话框由称为 NSModalPanelRunLoopMode 的特殊运行循环模式处理,请参阅 此处。
要安排调用,一种方法是使用该文档中解释的performSelectorOnMainThread:withObject:waitUntilDone:modes:;不要忘记在那里指定模态模式和默认模式。
您还可以使用 NSNotificationCenter 并指定运行循环模式,请参阅 此处的讨论。但是从线程环境中使用 NSNotificationCenter 是很棘手的,如 这里,所以我不推荐它。
在 10.6 上,您还可以使用
dispatch_async
。Short answer: Don't use modal dialogs.
Long answer: Modal dialogs are handled by a special run loop mode called
NSModalPanelRunLoopMode
, see here.To schedule a call, one way is to use
performSelectorOnMainThread:withObject:waitUntilDone:modes:
explained in that document; don't forget to specify the modal mode and the default mode there.You can also use
NSNotificationCenter
and specify the run loop modes, see the discussion here. But it's tricky to useNSNotificationCenter
from the threaded environment to start with as described here, so I don't recommend it.On 10.6, you can also use
dispatch_async
.