Desktop App Goes "Not Responding" on data load

I’m not sure if this is the right spot for this discussion as it covers a couple of different areas.

I’m working on desktop application that populates a listbox with a large number of records. The records are pulled in at random (this is on purpose) from a sqlite database using a loop based upon a specified number of iterations. After the import process begins, the application goes into a “Not Responding” status (this text is displayed in Windows and beachballs on OSX) after about five seconds or so. Eventually the process completed and the application comes out of “Not Responding” status.

From what I’ve read, this is somewhat “normal” when running a loop with a lot of iterations and that a thread/timer should be used. But when I’ve tried that, I eventually end up with a “threadaccessinguiexception” error since I still have to populate the listbox.

Any thoughts on how to get around this issue? Thanks!

Several thoughts:

You shouldn’t ever load that many records into a Listbox. It stalls the UI while it’s doing all that work and a memory hog. You should think about ‘paging’ your data.

This is a common approach and many applications and website use this. It’s faster, keeps the UI spry, and users are used to it.

I have a training video (along with source) on how to implement a Paging Data control for subscribers at This particular video creates one for web and one for desktop (same techniques).

To get around your ThreadAccessingUI exception you load the results from the loop into a property (dictionary, array, or otherwise depending on your columns), and then use a timer to load from the property to the listbox.

I would also recommend considering Bob’s comments on large amounts of data and listboxes.


Thanks a lot for your feedback. I got it working. I had to create a lot of App properties, but the process if flying now and I’ve been able to add a progress bar to boot. Thanks!

[quote=158684:@dave duke]Michael, add this to the inside of your loop


May help a little.[/quote]
I seem to remember people on the forums saying that it is not recommended to use DoEvents. The Xojo docs also states that it causes instability for desktop apps.

Oliver is right. Do not… That is, do NOT! use App.DoEvents in a desktop app. It’s meant to create an event loop in a console app, and I still wish Xojo would remove it from desktop apps.

Here’s my prediction: The new Framework will not have an equivalent.

A simple solution is to use the often overlooked “InitialValue” property of the listbox.

The following code adds 100,000 rows to a 2 column listbox in 2.5 seconds on my macbook.

dim s(99999) As string for i as integer=0 to s.Ubound s(i)=str(rnd()*100)+chr(9)+str(rnd) //tab delimited rows next Listbox1.InitialValue=join(s,chr(13))

Keep in mind that it will replace any previous values.
(not that displaying 100,000 rows is generally a good idea)

You can also use Cell for that purpose at any point:

Listbox1.Cell( -1, 0 ) = join( s, EndOfLine )

[quote=159662:@Kem Tekinay]You can also use Cell for that purpose at any point:

Listbox1.Cell( -1, 0 ) = join( s, EndOfLine ) [/quote]

This way i get only 1 column.
Only if i use:

Listbox1.Cell( -1, -1 ) = join( s, EndOfLine )

i get 2 columns and several rows.