Xojo.Core.Timer.CallLater question

Probably a stupid question but is it ok to use the below code to trigger a method 5 seconds later?

Xojo.Core.Timer.CallLater(5000, AddressOf test)

Or do I need to declare a timer first:

Dim t as new Xojo.Core.Timer t.CallLater(5000, AddressOf test)

Also, when the method has been called, is the timer released immediately?

CallLater is a class method (in Xojo “speak”: a shared method), so you don’t create an instance.

Just make sure that the object you’re calling is around when calllater is actually fired.

I ran into a problem where I needed to update the window once it was deactivated (not before) and so I used this, however when the window was closed, the deactivate event would fire, window would close and then the calllater event would fire. IIRC it would crash the app, or raise an exception.

The solution was to have a timer on the window, that way when the window was destroyed so was the timer.

I love CallLater. I use it all the time.
For example, I have a project where on every ListBox change, it takes about a second to retrieve and calculate the results. So when a user holds his finger on the down arrow to scroll through the Listbox, things are slow.

I fixed that by doing a CancelCall followed by a CallLater of 50ms in the Change event. So now they can scroll whatever they want but only if they stop scrolling, the process is actually started. I do this for search boxes etc. as well.

Things like this worked great until I started using CallLater from threads to start UI updates. Then I started to get random xojo.Core.IteratorException’s. Maybe these are the same Sam ran into.

I’m now using Karen’s/KAtkoSoft SingleActionTimer Class (Thanks Karen!) .
It’s pretty much the same thing (Variants instead of Auto’s) but it works much better for me. And since the source is there, I was able to make made some minor adjustments by doing a few HasKey and Nil checks to avoid issues.