I understand the concept of timers, but I’m having a problem getting this to work without a thread. I have a window that shows how many files are being loaded. It has a timer that copies text from a module’s property to the window’s static text. The timer is set to 500 milliseconds but it never fires. What do I need to add?
Make sure the mode is multiple (2) or it won’t fire more than once, if at all.
Yep. Fortunately that’s the default because I forgot to check.
Can you post the code you are using?
The timer’s
StaticTxt.Text = YDict.SplshWinText
Self.Refresh
In the open event
StaticTxt.Text = YDict.SplshWinText
needed = True
Timer1.Enabled = True
It gets called in the module like this
Dim ReBDictSplash As Splash
SplshWinText = "Re-Building Dictionary Files" + EndOfLine + Str(i) + " of " + Str(Ubound(DictList,1)) + " Files Loaded."
ReBDictSplash = New Splash
ReBDictSplash.Show
and updated like this
SplshWinText = "Finished Re-Building Dictionary Files"
ReBDictSplash.Refresh
Not sure what else to add.
Something seems missing here. Are you running a loop of some sort? Because a Timer only runs during idle time in the main thread, so a loop will block a Timer’s execution.
You shouldn’t need “Refresh” if it’s all working properly, btw.
Yes, the rule of thumb* is a call to Refresh means you’re doing something wrong.
- There are exceptions.
Grumble. It’s in a loop. Okay, that’s why it won’t fire. I can’t get the window to update with or without the timer.
Two ways around that. Put your code into a Timer that runs for x microseconds, then updates the field as it exits. You just have to keep track of it’s last position every time the Timer runs. OR, put your loop into a thread and use the Timer to update the field.
I figured out my problem. Dumb.
That’d mean a separate class or
???
About the thread, I also want to use it on Windows, and aren’t threads banned from updating the UI, or is there a way around it?
A thread should never update the UI. The thread should set properties that a Timer can grab to update the UI.
Do you know if there’s an example?
Never mind. It was easy to find.