StatusItem menu blocks main thread when it's opened. Workaround?
I've written an app for the Mac that is designed as a status bar item. However, when a user opens its menu fr开发者_如何学编程om the status bar, the main run loop is blocked until it's closed. Since this app responds to messages on a socket, it's a problem that it can't do anything while the menu is open.
I've tried setting the status item from a separate thread and scheduling the socket on a different thread, but no dice. Is there a good way to deal with this?
UPDATE:
I've resolved this now. I was using the NetSocket socket wrapper and its asynchronous nature made it very difficult to open and watch on a different thread. I switched to SmallSockets (another Objective-C socket wrapper) and because it is synchronous, I was able to open a socket and just watch it directly on a separate thread.
While the user is interacting with a menu the run loop runs in the event tracking mode. Attach your sockets to the NSEventTrackingRunLoopMode
mode too and they continue to run while the user interacts with the menu.
But putting the sockets on another thread should work too. If this did not work for you, you probably did something wrong, but without seeing the code I can't say.
精彩评论