Question popup progress bar

ghardy

Member
Joined
Mar 18, 2010
Messages
20
Programming Experience
10+
hi all,

i have a form that takes a long time to open (because of the volume of data and the devexpress scheduler controls on it). I would like to pop up a progress bar (embedded in a form) to show until the form loads and is finished loading.

i added two public methods in the My.MyApplication class...the form with the progress bar shows, but is stuck and doesn't animate.
i figure that i need to open this form in a separate thread, but have done no work with multithreading.


in the My namespace in the MyApplication class, i have these two subs:

Public Sub ShowProgressBar()
frmProgress = New frmProgressBar
frmProgress.Show()
frmProgress.Refresh()
End Sub


Public Sub HideProgressBar()
frmProgress.Close()
End Sub


and when i call the form that takes a long time, i call the following code:

My.Application.ShowProgressBar() '<----showing the bar

Dim frm As New frmProjectPhaseDetail(a, b, c)
frm.MdiParent = Me.ParentForm
frm.Show()


My.Application.HideProgressBar() '<-----form finished loading


is there an easy way to make this form always open in a different thread so that it will animate and show my "loading.." marquee? would this be the best solution for this?

thanks in advance!
 
If the UI thread is busy loading the other form then it can't refresh the progress form. A single thread can only do one thing at a time.

Is this the application's main form? I'm guessing so if you're sing the MyApplication class. If so then the functionality you want is already built into VB. Just select your progress form as the splash screen in the project properties.
 
not main form

this is well after the app loads. one particular screen takes a long time, which is why i want to just pop up a form with a marquee "progress bar", just showing that the app is doing something.

thx again
 
ok, i think i got it.....
here is my solution (found and modified from microsoft forum)


created a new class file in the MY namespace:


Friend Class PleaseWait
Implements IDisposable
Private mProgress As frmProgressBar


Public Sub New()
'mLocation = location
Dim t As New Thread(New ThreadStart(AddressOf workerThread))
t.IsBackground = True
t.SetApartmentState(ApartmentState.STA)
t.Start()
End Sub

Public Sub Dispose() Implements IDisposable.Dispose
mProgress.Invoke(New MethodInvoker(AddressOf stopThread))
End Sub

Private Sub stopThread()
mProgress.Close()
End Sub

Private Sub workerThread()
mProgress = New frmProgressBar()
mProgress.StartPosition = FormStartPosition.CenterScreen
mProgress.TopMost = True
mProgress.ShowDialog()
End Sub
End Class


and then to call it, i put this around the instantiation and showing of the form:

Dim wait As New My.PleaseWait
'----show the form
wait.Dispose()
wait = nothing
 
Back
Top