Indeterminate Progress Bar Loading Thread

I am trying to show a window with an indeterminate progress bar (LoadingProgressBar) when a user clicks ‘log in’ as feedback to end user to wait while app loads (caches data from database etc).

I tried doing this using a Thread but can’t get the progress bar to update.

Under App, I have a property called ‘LoadingWindow’. I also have a property which stores the MainWindow once logged in.

When the user clicks ‘Log In’, it does the following:

App.LoadingWindow = New LoadingWindow


Login 'some login method

Self.Close ' close login window and therefore thread once logged in

The Run event of the LoadingThread:

While App.MainWindow = Nil 'if window does not exist yet i.e. not logged in
  Me.AddUserInterfaceUpdate 'I tried passing with/without args as not important for me

The AddUserInterfaceUpdate event:


Where am I going wrong? I need the indeterminate progress bar to update while the Login method is running. Any help would be massively appreciated.

Don’t use a thread for this. You could do this simply event-based using the window Opening and Closing events and/or even before the window is even opened.

So you open the loading window and show it, with the indeterminate progress.
When the logged in is completed you close the loading window or stop the progress.

No thread needed. A thread just makes things harder and slower, use only when really needed (many loops for example)

Thanks. So I tried the following ignoring the thread when clicks ‘log in’:

App.LoadingWindow = New LoadingWindow


At the end of the Login method just before the Main application window is shown, I close the LoadingWindow and also the LoginWindow (Self).

The problem is the progress bar UI isn’t updating while the Login method is running.

What is the code in the login method?
If any loop, remove it. you need to use events and not loops (too long loop can choke the ui).

1 Like

There’s a database query to validate user, and then a quick while loop (1 row) getting data from the returned RowSet columns.

After the Login method completes and the MainWindow is created and shown (before LoadingWindow is closed), in open event of MainWindow, it caches data for dropdown lists by querying a database and looping through results. So I’m guessing this is what is choking the UI.

if you show some code we could help, without code it’s impossible to direct you to the solution swiftly.