473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is there a better way: Displaying a Working Dialog

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

showDelay()

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
aList.Add(i)
Application.DoEvents()
Next

Debug.Print(i.ToString)

Next

Me.Button1.Enabled = True

endDelay()

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",
thisExe.GetName.Name))
imageFirst = System.Drawing.Bitmap.FromStream(myStream)
myStream =
thisExe.GetManifestResourceStream(String.Format("{ 0}.imageSecond.bmp",
thisExe.GetName.Name))
imagesecond = System.Drawing.Bitmap.FromStream(myStream)

f = New splashForm(imageFirst, imagesecond)

f.Show(Me)
f.Process(False)

End Sub

Private Sub endDelay()

If inDelay Then
f.Stop()
f.Dispose()
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.
InitializeComponent()

' 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
Else
Me.BackgroundImage = imageFirst
End If

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

EndDelay = False

worker.RunWorkerAsync()

End Sub

Private Sub doWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs)

'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,
System.ComponentModel.BackgroundWorker)

DontStop = True

Do While DontStop

SyncLock (Me)
DontStop = Not EndDelay
End SyncLock

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

worker.ReportProgress(0)

Threading.Thread.Sleep(50)

Loop

End Sub

Private Sub progressChanged(ByVal sender As Object, ByVal e As
System.ComponentModel.ProgressChangedEventArgs)

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
Else
Me.Opacity -= 0.05D
End If

Me.CenterToParent()

End If

End Sub

Private Sub runWorkerCompleted(ByVal sender As Object, ByVal e As
System.ComponentModel.RunWorkerCompletedEventArgs)

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

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

End Sub

End Class
Aug 11 '06 #1
0 1065

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Rich Tasker | last post by:
I have a strange situation. A simple call to MessageBox.Show("XXX", "YYY") does not display the message in the messagebox with a visible font. Based on the content of the messagebox, the box...
1
by: Sherwood | last post by:
Greetings, I have a "newbie" question regarding C#.NET. I am using the "Windows Application" template and am simply trying to display a second form ("frmInstructions") once the user clicks a...
2
by: Walid Koleilat | last post by:
I have created an assembly and assigned a strong name to it. However I want to reference it from another application and i want its name to appear in the add reference dialog box, I think I should...
3
by: sonic | last post by:
Hi, displaying information on a page as MS Word document seems to be as simple as: //OnLoad Response.ContentType = "application/msword"; Response.Write ( MyContentString ); (this assuming...
4
by: mpreston | last post by:
I'm following the example from the MSDN library on how to create modal dialog boxes in C#, but something isn't working properly. If I create a modal dialog box and show it using ShowDialog(), the...
9
by: Andrew Kidd | last post by:
Hi, I've just been working through several examples of how to create Master pages and then create content pages which are linked, but I cannot see the Master page when I'm viewing the content...
1
by: henning | last post by:
Hello, I'm involved in the development of a set of web pages that are meant to be used on touch screens. We use ordinary HTML, PHP and javascript for the pages. I wold prefer a serverside...
1
by: NBKMNDN | last post by:
Hi frends, In my C# application im creating a new excel sheet and im inserting some data into this excel sheet, and im trying to save the file with the help of method SAVE AS. But it doesnot...
1
by: Michael Bray | last post by:
I'm trying to display an image on an ATL Dialog form in VS2003... I think I am able to load an image (a GIF) w/ CImage.Load, and I'm trying to call the SetBitmap followed by Invalidate on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.