当模式对话框打开时如何接收通知

发布于 2024-09-14 01:37:39 字数 324 浏览 3 评论 0原文

我需要向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤蝉 2024-09-21 01:37:39

简短的回答:不要使用模式对话框。

长答案:模态对话框由称为 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 use NSNotificationCenter 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文