Slow Execution When Minimized (But Only in OS X)

I am writing an app to control a Midas Mixer via UDP. The program basically receives a command string, I change the string a little and then send it back to the mixer.

The problem is in OS X. When the program does not have the focus or when it is minimized, it slows down to a crawl. All of the commands “Stack Up” waiting to be processed. If I restore from minimized or set the focus back to the window, it processes all the commands very quickly. I should mention that the program isn’t trying to update the user interface or any graphical controls. It is simply sending and receiving strings over UTP.

When I run it on Windows, it works exactly like it should regardless of its windows state. I have added a thread control and executed the code within it but it did not help. Any advice would be greatly appreciated. I’m really stuck.

Thanks,
-Marty

Sounds like you don’t want your App to go into Nap mode. (check with the activity monitor)
There are several ways to prevent App Nap. I do it with writing NSAppSleepDisabled = False to NSUserDefaults. If find this the easiest and it works for me but I don’t think it is the official way to do it.

Thanks,
It even does it in debug mode. Do you think it could still be AppNap? I’m pretty sure I disable that system wide when I had Mavericks. I’m running Yosemite now.

Yes, in debug mode as well.
You can check it in the activity monitor.

Try to put this in your .Open event

Declare Function standardUserDefaults Lib "Foundation.framework" Selector "standardUserDefaults"(NSUserDefaultsClass As Ptr) As Ptr Declare Function NSClassFromString Lib "Foundation.framework"(ClassName As CFStringRef) As Ptr Declare Sub setBool Lib "Foundation.framework" Selector "setBool:forKey:"(NSUserDefaults As Ptr, Value As Byte, Key As CFStringRef) Static standardUserDefaultsPtr As Ptr = standardUserDefaults(NSClassFromString("NSUserDefaults")) setBool(standardUserDefaultsPtr, 1, "NSAppSleepDisabled")
With this, your App needs to run once though. After that, it shouldn’t go into AppNap anymore.
(Maybe someone else knows a better way to just switch it on and off instead of using NSUserDefaults)

That fixed it!
Thank you Marco! I truly appreciate your help!

Best Regards,
-Marty

Yup App Nap is the problem. The official way to control App Nap is via the NSProcessInfo classes, I have some Xojo code on this page http://www.ohanaware.com/xojo/ or if you have the MBS it also has the classes.

Ideally what you’re meant to do is to notify the OS when you’re about to perform a task that requires the app to be awake and then again to inform it once it can go back to sleep. But as you’re app pretty much needs to be constantly awake, then you may want to set this on App open.