Progress Wheel example code?

I am a newby. I have an app that populates a listbox. I would like to display a progress wheel during this process. I understand that to display the progress wheel turning the app needs to be idle. I think I need to use a thread for this. I have no idea how to use a thread. I have searched the web, docs, examples and this forum but have not been able to find any sample code to make this happen. Does anyone have any sample code that might help me.
Thank you

A progressWheel should animate even when you’re doing something like adding items to a listbox, unless you’re doing it a really tight loop that doesn’t give the app much spare time. In that case, a thread would work and it’s pretty easy.

Just add a new thread to your app (via the Library) and put your listbox-loading code in it. Then call the thread, e.g thread1.run (assuming the that’s the thread’s name), to have it load the listbox.

Another idea: I haven’t tried this, but I wonder if calling progressWheel.refresh might force it to animate? If so, you could call it periodically during your listbox-loading routine.

David:

how many Rows do you add into the ListBox ? (that urges you to place a “waiting” mechanism for your user ?)

Adding around 1,000 Rows (reading folders from a master folder) does takes here less than a second; in fact, the user do not realize he was waiting (how many Rows were added).

Before you go down that path… Updating a UI element from a Thread can lead to application instability. As a matter of fact, an Exception is raised if you attempt to do this in a Cocoa app.

If you are going to use a thread, use it to push the data you want to display into an array and then a Timer to periodically pull from the array and push onto the Listbox.

Marc I tried the progressWheel.refresh, since that would be the easiest. The progressWheel appeared but it was frozen. This method added a lot of time to the routine.
Emile, I think doing nothing as you suggest is the correct path. Populating the list does not take that long. And I am using an ancient MacBook so I suspect it will run even faster on real computers. Better to use my time on more important coding.

Thank you all for making this forum such a great resource.

Yeah, I wasn’t sure if it would work. BTW, you shouldn’t call it every time through the loop, but only occasionally. I’ve done things like this to update UI during a long loop (assuming i is my counter):

if i / 1000 = i \\ 1000 then // update a progress bar or whatever

The actual numbers used will depend on the size of your loop and length of each task, but in this example it will only update the UI once every 1000 times through the loop.

Another idea (though it sounds like you don’t need this as you said your listbox isn’t that big) is to use one of the third-party “data on demand” listboxes. Those only load data as it needs to be displayed, so they’re much faster for this kind of thing (useful when your listbox has a million items, for instance).