I have an interesting issue. I’m building for macOS, 64 bit. I’m using a thread to load a listbox with items from an array. This array is huge it may contain 100,000 records or more.
In my old 32 bit version, this was no problem. Performance was fast. I took about 2-3 seconds to load the listbox.
Now I am using 64 bit, with a threaded task using the UpdateUI method. Here’s the interesting problem:
If I load the data from the array using a non-threaded method, it is fast. The UI locks up for a few seconds, and then the rows appear, and all is well. However, I don’t want the UI to lockup, even for a second. So I put this in a thread. When I do, it now takes over a minute (!!) to populate the listbox! What is going on here?
Test for yourself. Make a new project. Add a listbox to the window, and use this code in the Open even:
for i as integer=1 to 200000
ListBox1.addRow "ABCDEFGHIJKLMNOPQRSTUVWXYZ "+cstr(i)
next
Run the project. Boom, the listbox populates in a couple seconds. Now use a thread:
Add Threaded Tasks to your project. Add a thread to the main window. Change the Open even to read
Thread1.run
Set Thread1’s subclass to Task
Add this code to the thread’s Run event:
for i as integer=1 to 200000
Me.UpdateUI("boxAddRow":"ABCDEFGHIJKLMNOPQRSTUVWXYZ "+cstr(i))
next
Add this code to the thread’s UpdateUI event:
if args.HasKey("boxAddRow") then
dim rowData as string=args.value("boxAddRow").StringValue
ListBox1.addRow rowData
end if
Not only does the process now take much, much longer, but the UI locks up, you get a spinning beachball, and the whole thing freezes. After awhile, the rows will eventually load and the program will respond again.
Just curious what the reason for this is, and if there is a solution?