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
App.LoadingWindow.Show
LoadingThread.Start
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
Wend
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)
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.