1

I'd like App Nap to be disabled by default for my Mono Mac application as it ships.

I've found a few references to this this question, but NSProcessInfo.beginActivityWithOptions doesn't appear to exist in the MonoMac classes.

Is there any way to achieve this?

Community
  • 1
  • 1
mattdwen
  • 5,288
  • 10
  • 47
  • 61

1 Answers1

2

You will need to store the Activity object that is returned from BeginActivity somewhere:

NSObject myActivity;
const string myReason = "Hacking the planet";

Then when you want to prevent app nap from occuring:

// Prevent auto-sleeping
myActivity = new NSProcessInfo().BeginActivity(NSActivityOptions.IdleSystemSleepDisabled|NSActivityOptions.SuddenTerminationDisabled, myReason);

There are lots of combinations of NSActivityOptions that you can use depending upon your application requirements.

And when you are done with your processing:

// End the battery draining activty
new NSProcessInfo().EndActivity(myActivity);
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • It's a MonoMac project, and still supporting 10.6 (!). I might have to fork it off for the newer versions. – mattdwen Nov 08 '15 at 19:53