By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

Is there a better way: Displaying a Working Dialog

P: n/a
Hello Everyone,

Just curious how far off the mark I am with my Working Dialog. Any
improvements are welcomed.

Scenario, we have an application (vb'05) that at known times performs tasks
that take some time to process. During those times, I would like to display
a dialog that informs the user that work is occuring.

We have a base form that all other forms derive from. It is in this form
that I put the logic for enabling and disabling the wait dialog.

Here is a simple sample use:
class form1
inherits baseForm

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click


Me.Button1.Enabled = False
Dim aList As ArrayList = New ArrayList

For i As Integer = 1 To 10

For j As Integer = 1 To 10000
'Hurt the processor



Me.Button1.Enabled = True


MsgBox("Job's Done!")

End Sub

end class

Here is my code

'--==Class baseForm.vb==--

Protected f As splashForm
Protected inDelay As Boolean

Private Sub showDelay()

If inDelay Then Exit Sub
inDelay = True

Dim imageFirst As System.Drawing.Bitmap
Dim imagesecond As System.Drawing.Bitmap
Dim myStream As System.IO.Stream
Dim thisExe As System.Reflection.Assembly

thisExe = System.Reflection.Assembly.GetEntryAssembly
myStream =
thisExe.GetManifestResourceStream(String.Format("{ 0}.imageFirst.bmp",
imageFirst = System.Drawing.Bitmap.FromStream(myStream)
myStream =
thisExe.GetManifestResourceStream(String.Format("{ 0}.imageSecond.bmp",
imagesecond = System.Drawing.Bitmap.FromStream(myStream)

f = New splashForm(imageFirst, imagesecond)


End Sub

Private Sub endDelay()

If inDelay Then
End If

inDelay = False

End Sub

'--===Class splashForm.vb==--

Public Class splashForm

Private EndDelay As Boolean
Private OnFirst As Boolean = True

Private imageFirst As System.Drawing.Bitmap
Private imageSecond As System.Drawing.Bitmap

Public Sub New(ByVal oimageFirst As System.Drawing.Bitmap, ByVal
oimageSecond As System.Drawing.Bitmap)

' This call is required by the Windows Form Designer.

' Add any initialization after the InitializeComponent() call.
imageFirst = oimageFirst
imageSecond = oimageSecond

Me.BackgroundImage = imageFirst
EndDelay = False

End Sub

Public Sub [Stop]()
EndDelay = True
End Sub

Public Sub Process(Optional ByVal ShowProcessing As Boolean = True)

Dim worker As System.ComponentModel.BackgroundWorker

worker = New System.ComponentModel.BackgroundWorker
worker.WorkerReportsProgress = True
worker.WorkerSupportsCancellation = True

If ShowProcessing Then
Me.BackgroundImage = imageSecond
Me.BackgroundImage = imageFirst
End If

AddHandler worker.ProgressChanged, AddressOf progressChanged
AddHandler worker.RunWorkerCompleted, AddressOf runWorkerCompleted
AddHandler worker.DoWork, AddressOf doWork

EndDelay = False


End Sub

Private Sub doWork(ByVal sender As Object, ByVal e As

'Temp var used as a flag
Dim DontStop As Boolean

' Get the BackgroundWorker object that raised this event.
Dim worker As System.ComponentModel.BackgroundWorker = CType(sender,

DontStop = True

Do While DontStop

SyncLock (Me)
DontStop = Not EndDelay
End SyncLock

'Trace.WriteLine(String.Format("Processing and dontstop = {0}",




End Sub

Private Sub progressChanged(ByVal sender As Object, ByVal e As

Static GoNorth As Boolean

If Not EndDelay Then

If Me.Opacity >= 1D Then GoNorth = False
If Me.Opacity <= 0.01D Then GoNorth = True

If GoNorth Then
Me.Opacity += 0.05D
Me.Opacity -= 0.05D
End If


End If

End Sub

Private Sub runWorkerCompleted(ByVal sender As Object, ByVal e As

Dim worker As System.ComponentModel.BackgroundWorker = CType(sender,

RemoveHandler worker.ProgressChanged, AddressOf progressChanged
RemoveHandler worker.RunWorkerCompleted, AddressOf runWorkerCompleted
RemoveHandler worker.DoWork, AddressOf doWork

End Sub

End Class
Aug 11 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.