Progress Bar and UI

Can someone please explain to me how to get a progress bar to work in the following context

I have loaded a database into a listbox, and the user can then do a lot of manipulation on it. The user then wants to save the changes back into the database. Easy enough to do, but the updating takes time and I would like to have a progress bar show how it is getting on.

Solution 1. Put the progress bar on a window and update the progress bar value as the main process writes the data out from the listbox. Writing updates works fine, but progress bar does not update, despite having an associated timer, in fact window just says black until the writing out is finished because the main process hogs the processor.

Solution 2. Taking advice from all the other posts, I put the database update into a thread, and the progress bar works fine in a mock up where the database update is just a repeated app.sleep 100ms. Now I put the real database code in the thread and bang it gets a UI update exception because I am referring to the listbox - note, not updating it, just trying to read the contents in order to update the database from it.

Any ideas how I can solve this seemingly impossible conundrum?

I’m running Xojo 2016.1 on OSX

why not just a Progress Wheel?

Don’t load directly the listbox. Put the data in an array, then after the thread is done, copy that data to the listbox out of the thread. Alternatively you can do that in a timer during the load, at the same time you move the ProgressBar.

You cannot access the UI in any way, neither get or set.

Thanks Michel

that sorts the UI problem, but I still have two issues as a result

  1. How do I put the main window / process on pause to stop the user continuing to make changes while the separate thread is writing the copy out, but at the same time not stopping the progress bar from updating via the timer thread associated with the main process

  2. How do I let the main process know and un-pause it when the thread has finished updating the database and the user is free to make more modifications

Use a modal window to display your progressBar and a “please wait” message. It will prevent access to the main window.

Close the modal window :slight_smile:

Many thanks again Michel

All now appears solved. Modal window should have been the obvious solution, but in trying to solve the other problems I had a too complex set of semaphores which I have been able to ditch with the simple use of a modal window!