Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X application slows down when its window has not focus

I am developing a MAC OS X application with SWIFT and ObjC using XCode 6.1. The application is a server and it uses a CFSocketRef in the main thread run loop.

When the application window has not the focus on it the application slows down and the server receives the messages from the client with delay.

Is this normal (an app with no focus slows down)? If it is normal is there a way to set the main thread priority so that if the app has no focus it continues running in the same way?

like image 247
cmarlowe88 Avatar asked Dec 30 '25 22:12

cmarlowe88


1 Answers

In my controller class I have added in the awakeFromNib function the beginActivityWithOptions and than in the applicationWillTerminate the endActivity like the following

class ConsoleController: NSObject
{
  var process : NSProcessInfo?
  var activity: NSObjectProtocol?
  override func awakeFromNib()
  {
    process = NSProcessInfo.processInfo()
    activity = process!.beginActivityWithOptions(NSActivityOptions.UserInitiated, reason: "Good")
  }
  func applicationWillTerminate(notification: NSNotification)
  {
    process!.endActivity(activity!)
  }
}
like image 70
cmarlowe88 Avatar answered Jan 01 '26 15:01

cmarlowe88



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!