I just want to give kudos to the Xojo team for the most awesome API implementation of timers in the new framework. So happy they are available on the desktop now.
Being able to use the Xojo.Core.Timer.CallLater methods without having to set up a timer, add handlers, etc. is just brilliant. And having one of the shared methods allowing you to add a parameter for the method as well is just great. Really nice job guys.
[quote=182017:@Jon Ogden]What would actually be nice would be an arbitrary number of parameters. Then nearly any method could be used with these timer methods or without them.
You can pass along a class of your own creation, so you can create an arbitrary number of parameters that way. Or pass a Dictionary or an array of Auto.
It takes only one Auto but you can encapsulate whatever you want in it.
Untested but something like:
Dim Parms(), Parameters As Auto
Parms.Append(arg0)
Parms.Append(arg1)
Parms.Append(arg2)
Parameters = Parms()
Xojo.Core.Timer.CallLater(5000, AddressOf MyMethod, Parameters)
And catch Parameters on the other end and unpack them:
Dim Parms() As Auto = Parameters
Dim arg0 As String = Parms(0)
Dim arg1 As Integer = Parms(1)
Dim arg2 As Text = Parms(2)
One thing to watch out for, is the object who’s method you’re calling going out of scope. In my limited testing, I’ve found that even with WeakAddressOf this can cause an application crash on El Capitan.
I worked around it by creating an encapsulating method which places a weakref on an array stack, then in the method it processes the first object (if it can resolve it) and then pops it off the stack.
Hmm now you mentioned that, I guess that’s the reason why I constantly ran into xojo.Core.IteratorException’s on xojo.Core.Timer.CancelCalls.
Because of those, I’m using Karen’s PersistentTimer. I had make a few tweaks (If .Haskey then .Remove) but it’s running super stable.
With things like this (where the errors happen at random and you don’t know the underlying reason) it is extremely hard to come up with an example or stripped down version of a larger project.
And when you do decide to file a bug report and explain it the best way possible, it is shot down because of the missing example.
Not very motivating.
Okay, I’ll try to throw together a sample project. I didn’t actually consider it a bug as the object (window in my case) was released before the timer could fire.