I have a couple of timers in my Xojo program that send out a “heartbeat” message via a TCPSocket every second, to let the app they’re connected to know that the Xojo app is still “alive”.
Works fine when the Xojo app is on the screen. If I minimize the app or the screensaver comes on, after about 1 minute, the timers stop. They restart again after about 10-20 seconds, but that’s enough time for the connected app to feel that they’re disconneted.
Is it normal for a timer to pause (or maybe the app is sleeping) after it’s not in the foreground for a minute or so?
Other than forcing my app to never minimize, is there a way to keep a timer from “sleeping”?
Oh, this is when running on MacOS. I haven’t tested to see if this issue happens on Windows, but I will.
Looks like going into terminal and typing defaults write com.checkcheckonetwo.YammieRemote NSAppSleepDisabled -bool YES
does the trick.
Would I be able to shell that command?
I do have MBS.
Do you know if separate threads are affected by AppNap? I was thinking about moving the heartbeat to a separate thread or maybe a shelled console app…
Not 100% on Variable scoping and Class destructors… If I add a property for the MainWindow of AppNapToken As AppNap.AppNapToken
and in MainWindow.Open Event: AppNapToken = New AppNap.AppNapToken("Keep Alive")
Then in MainWindow.Close Event: AppNapToken = Nil
Does setting the variable to Nil call the Destructor, or is there another way classes are destroyed in Xojo?
Scope and destructors arent inherently tied together
SCOPE
This refers to the places where an item (method property etc) can be referenced
ie/ using just local variables we can see the effects
for i as integer = 1 to 10
// using i is LEGAL here as i was defined in a way it is IN scope
dim j as string
// using j is LEGAL here as j was defined in a way it is IN scope
next i
// using i is NOT legal here as i was defined in a way it is only available in the loop
// using j is NOT legal here as j was defined in a way it is NOT in scope (it literally doesnt exist)
When it is things like properties & methods they have a different way of denoting what can and cannot access them
a PUBLIC property on an instance of a class can be manipulated by any code that has a reference to the instance
a PROTECTED property can only be altered by code IN the instance, or a subclass
a PRIVATE property can only be altered by code IN this class (not subclasses)
A property on a window will be “in scope” for any code on that Window
DESTRUCTORS
A destructor for an object will be run AS SOON AS the reference count to an instance is set to 0
So if your code setting AppNapToken = NIL IS the last reference (ie/ its not held in any other statics or other properties on the window) then setting the reference to NIL SHOULD make the destructor run right away