I have a need to call a function “later”. For example I may want to wait every 12-24 hours and then check if the solution is still activated (from a licensing perspective).
I could use timer.CallLater, or set a timer with a long period.
Is that the best way to do it or is there a more elegant solution?
I don’t think that is a good idea, what if the application is closed by the user?
What about having a separate application that is called by the Windows scheduler or crontab on Mac or Linux.
Not debating the strategy of checking activation. I have all those other issues covered. What I’m concerned with is someone leaving the app open forever and deactivating online.
My question is about scheduling a call to a function.
If what you are doing is license checks, then presumably you also check when the app first launches, covering the scenario @Ian_Kennedy describes. What I would suggest is using a random value for the timer (with the min/max times whatever you are comfortable with using). This helps frustrate those who rely on a 24 hour period to use the app if they have circumvented other checks.
Nether am I. What I’m saying is that there is no real way for an app to run its self at a given time of the day. All you can do is link it to app startup or some defined event that your app is in control of. CallLater only creates a timer that will fire after a set period, while the app is running. Once the user quits the app the CallLater is completely destroyed. It won’t suddenly cause the app to start up again the next day in order to complete a process.
NO, just use a normal timer, with a small period, like 5 mins, and in the run event make an IF its time to check licence. You can have the 24 hours or as Douglas says, a random period.
I’m good with them quitting. If they do and re-launch then I have that covered.
that’s a good suggestion for sure.
I just wasn’t sure about using timers for longer periods. I see another response suggesting checking very 5 minutes (or whatever).
likely what I’ll do is setup a time to check again being somewhere between 4 and 12 hours and then have a regular running timer see if the threshold is met, check again and then reset.