[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Diplaying a Load message while main form is Loading

My app has a sub, which calls the Login form where my users need to enter Login Info to be able to access the application,
once they pass it opens the Main Window of the App. All that works fine except for the factm that the mainform loads a
large set of data on load which can cause a 10 - 30 sec delay until the form is displayed, depending on serverload and
connection speed.
What i would like to do is open a temp window which will display a message telling the user to
wait while the mainform is beeing loaded, then when the mainform is loaded i want to dispose this form.

i am looking for some samples or help where to hook in the load and dispose of this form or if there are better ways to do this

  • 5
2 Solutions
I'd say that when your main form is loaded... put the code that loads the dataset into a seperate thread maybe... start that off... then right on the next line, display a modal form saying "Please Wait"... remove the close buttons and such.

Make sure the wait form is declared at class level (I think that's the correct name for it... i.e. outside of a sub/method)  so that when the other thread has completed loading the data, it can close the form.  I'll test this works in a moment... and post up some code to work with
Ok... here's a crude "Waiting" form


Public Class frmWait
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 16.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(0, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(296, 120)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "LOADING"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(292, 120)
        Me.ControlBox = False
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmWait"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "frmWait"

    End Sub

#End Region
End Class


Now, in your main form after logging in, I've put this in the Load event, you might change this for wherever the main form starts loading data...

    Private frmWaiting As frmWait

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim thdDataLoad As New Threading.Thread(AddressOf LoadingData)
        frmWaiting = New frmWait
    End Sub

    Private Sub LoadingData()
        Threading.Thread.CurrentThread.Sleep(5000)     ' This was just for testing... this would obviously be replaced by your code that loads all the data
    End Sub
Give the other experts a chance to put in their different ideas... they probably have better ones, or may find that mine is not a "good" way of doing things.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

you may want to set the borderstyle of the Waiting form to "none" so that the user can't move it around the screen.

Also set the cursor of the Waiting form to the hour glass or pointer/hourglass (app starting)

Obviously, you can customize the waiting for to fit your style... maybe some sort of animation... up to you
Your method looks fine to me s-twilley :-)
Thanks... Im still not 100% confident with doing multi-threaded apps... especially when working other two classes. I've started using delegates and such, but they've all been pretty simple so I've not really come across situations where problems might arise across different threads
My code for the wait form -- also use a second thread, different structure in coding:

    Dim t1 As Threading.Thread
    Dim f As frmWait

    Private Sub newForm()

        f = New frmWait

    End Sub

    t1 = New Threading.Thread(AddressOf newForm)

    myDataAdapter.Fill(myDataSet)  ' Your code for loading data

    f = Nothing
    t1 = Nothing

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now