在 Launch Daemon 中使用 Appkit 框架

发布于 2024-12-13 17:23:50 字数 351 浏览 0 评论 0原文

我想使用 NSWorkspace 检查应用程序是否启动或关闭

但该进程是 Launch Daemon,并且 Apple 文档称其不是线程安全的。

但是,使用 Workspace 的代码部分不会在启动或登录时执行。它会在通过 BSD 通信从其他应用程序接收到一些命令后执行,并且进程是没有 UI 的后台进程?

在这种情况下使用Appkit框架安全吗?只有 NSWorkspace API 而没有其他 API?替代解决方案是轮询?你的建议是什么?

I want to use NSWorkspace to check if application is launched or closed.

But the process is Launch Daemon and Apple documentation says its not thread safe.

However, the part of code that makes use of Workspace will not be executed at start up or login time. It will be executed after some commands received from other application via BSD communication and process is background process without UI?

Is it safe to use Appkit framework in this situation? Only NSWorkspace API and no other? Alternate solution is Polling? What is your suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

紙鸢 2024-12-20 17:23:50

一般来说,您可以使用任何非线程安全的代码,只要您在任何给定时间只执行 unthreadafe 操作的一项操作即可。我会继续尝试一下,只是要注意,无论你在做什么,你都不能同时做,如果你绝对需要同时做某件事,你可以尝试在代码周围抛出几个 @synchronized 块,或者在回调中长时间运行的后台进程或委托调用。

Generally you can use any code that isn't thread safe, as long as you are only doing one operation of whatever the unthreadafe operation is at any given time. I would go ahead and try it, and just be aware that whatever you are doing you can't do concurrently, if you absolutely need to do something concurrently you can try throwing a couple of @synchronized blocks around the code, either in callbacks of a long running background process, or delegate calls.

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