Resolved Progress Bar display?

Joined
Aug 14, 2008
Messages
7
Programming Experience
Beginner
In my application there is a lot of pre-processing of data at start-up. From the time the application launches until the form actually displays is around 9 seconds. Is it possible to display a progress bar before the form loads to indicate how far though the data processing the application has progressed?

Nine seconds is a really long time for people to have faith an application is loading these days. :D yet, I cannot let them have any controls until the dataset is ready.
 
Last edited:
I don't really agree with that approach. VB already has splash screen functionality built in so you should just put the ProgressBar on your splash screen. You can then declare a method in the splash screen that will advance the ProgressBar, either by taking a specific value as an argument or else just by performing a step. The main form simply calls that method to update the ProgressBar on the splash screen.

There are two small points to note here:

1. The SplashScreen property of the application is type Form, because you can use any form as the splash screen. As a result, you must cast the splash screen as its actual type in order to access its specific members.
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim splashScreen = DirectCast(My.Application.SplashScreen, ProgressSplashScreen)

    'Do something.

    splashScreen.UpdateProgress()

    'Do something else.

    splashScreen.UpdateProgress(50)

    'Do the last thing.

    splashScreen.UpdateProgress(100)
End Sub
2. The splash screen is created on a secondary thread, which is how it can be displayed and yet the UI thread still be free to load up the main form. As a result, the methods you call from the main form will have to be marshalled to the thread that owns the splash screen in order to update the UI, i.e. the ProgressBar.
Public Sub UpdateProgress()
    If InvokeRequired Then
        Invoke(New MethodInvoker(AddressOf UpdateProgress))
    Else
        ProgressBar1.PerformStep()
    End If
End Sub

Public Sub UpdateProgress(value As Integer)
    If InvokeRequired Then
        Invoke(New Action(Of Integer)(AddressOf UpdateProgress), value)
    Else
        ProgressBar1.Value = value
    End If
End Sub
Also note that I have overloaded that UpdateProgress method just for the purposes of this example. Most likely you would only need one or the other, not both.
 
Back
Top