Using threads instead of a timer

I think I know the difference between the two? But why do so many people use threads instead of a timer, I am particularly thinking about the issue of accessing UI from a thread. What’s the problem with placing all of your code in a timer instead of a thread?


A timer still runs on the main thread. Think of a thread as a checkout line at a grocery store. One person at a time (although on a computer it goes much faster!). Doing things in a thread creates another checkout line. It’s not as “separate” as multiple grocery store checkout lines, but it is getting separate attention.

It takes some experience in REAL/Xojo to get used to how often it blocks commands from different areas. If you have a function taxing the CPU, timers can get blocked from firing when they are scheduled to. Taking the grocery store checkout line analogy, that assumes the most strict possibility. REAL/Xojo isn’t as perfectly strict as a perfect serial-line (say you call a Refresh method within routine, it’s going to yield somewhat), but you should assume the worst.

Threads unclog things, but one hates using Threads constantly. Visual Basic (at least the v5 and v6) yielded much more than REAL/Xojo does. When I say “yield” I mean rearranging the line to address “pressing needs” in the order the attendant feels most appropriate.

Getting back to a Timer, using a Timer to fire a set need, like updating the UI, may rearrange to your favor the internal priority the main thread (our grocery attendant) takes things into account. Maybe not.

(I’m sure I’m going to get corrected here, but that’s how I see it.)