Although this is happening within a Xamarin.Mac project, I think the issue is more to do with MacOS, as the signs are that of App Nap.
In my AppDelegate.cs
file, I have this:
public override void DidFinishLaunching(NSNotification notification)
{
_activity = NSProcessInfo.ProcessInfo.BeginActivity(
NSActivityOptions.Background |
NSActivityOptions.LatencyCritical,
"You charge $3,500AUD for this laptop and yet " +
"can't provide enough resources for a smooth " +
"operation of this app in the background? " +
"Eat a d#@k Apple."
);
// ...
I tested the above with the following that runs every ~1s:
var now = DateTime.Now;
var now_str = now.ToString("HH:mm:ss.fff");
Debug.WriteLine(now_str);
var idle_time = now - _prevTime;
if (idle_time.TotalMilliseconds > 1200)
{
Debug.WriteLine("FFSakes Apple!");
}
_prevTime = now;
await Task.Delay(1000); // yes yes, I know timers aren't precise, hence why I said '~'1s.
After hours of banging my head, I decided to run the app, put it in the background and go have a nap. Turns out, so did my app. In the 1.5 hours I left it on, it did this:
19:23:29.040
19:23:30.041
19:56:07.176
FFSakes Apple!
19:56:08.196
19:56:09.196
...
A lag of over half an hour!
Question 1: Why?
Question 2: How do I get around this?