Main Thread Runloop gets blocked on opening nsmenu

房东的猫 提交于 2019-12-01 23:46:59
Dave DeLong

What I'm guessing is that you have an NSFileHandle that represents the NSTask's stdout, and you've asked it to -readInBackgroundAndNotify.

The problem with this, as you've found, is that this only notifies when the runloop is in the default mode. If the runloop enters another mode (such as when a menu is open), then your notifications will queue up on the main runloop and will wait until the runloop re-enters the default mode.

What you want to use instead is the -readInBackgroundAndNotifyForModes: method, to which you would pass an array containing both NSDefaultRunLoopMode and NSEventTrackingRunLoopMode. This would indicate to the runloop that you want to be notified of any available data when the runloop is either in the default mode or the event tracking mode.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!