1

I'm working on an application, There are several NSWindows in this application and one StatusItem in order to access any of NSWindows when they are not open. Some of these windows continuously updating their interface with new numbers and statuses. The problem is whenever I'm clicking the StatusItem in the System Status Bar it's blocking the updates on the windows and I can't see any updates until I close the StatusMenu.

Abcd Efg
  • 2,146
  • 23
  • 41

1 Answers1

3

This is about Run Loop Modes.

Deferred operations that run on the main thread are typically scheduled for NSDefaultRunLoopMode of the main run loop which means to not run when a menu or a modal dialog is open. You need to use NSRunLoopCommonModes instead, which will allow them to run in both default and event tracking (menus, dialogs) modes.

For example:

  • if you are using NSTimer to fire update events, instead of scheduledTimerWithTimeInterval, use timerWithTimeInterval in combination with [[NSRunLoop currentRunLoop] addTimer:theTimer forMode:NSRunLoopCommonModes].

  • if you are using performSelectorOnMainThread:withObject:waitUntilDone:, instead use performSelectorOnMainThread:withObject:waitUntilDone:modes:, passing [NSArray arrayWithObject:NSRunLoopCommonModes] for the modes: argument.

hamstergene
  • 24,039
  • 5
  • 57
  • 72
  • Thank you for your answer. Since most of my app code is written, is there a way to apply NSRunLoopCommonModes to selectors without going through this process or somehow changing the StatusMenu runloop mode? – Abcd Efg Jan 10 '13 at 16:49
  • @AbcdEfg I'm afraid no. There is no way to let status menu run in other mode, you have to change the way you schedule timers and selectors. – hamstergene Jan 10 '13 at 18:17