Show processing progress

  • Thread starter Thread starter Shawn Regan
  • Start date Start date
S

Shawn Regan

Hello,

What is the best practice to show a window/form of some
animation while processing is going on in the back ground.

I want the user to see something while some processing is
taking place.

TIA
 
Shawn Regan said:
What is the best practice to show a window/form of some
animation while processing is going on in the back ground.

I want the user to see something while some processing is
taking place.

In a new project, add a button to the Form. Also add the following code:

Private m_Thread As MyThread

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

m_Thread = New MyThread
AddHandler m_Thread.Progress, AddressOf OnProgress
AddHandler m_Thread.Done, AddressOf OnDone
m_Thread.Start()
End Sub

Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)

Private Sub OnProgress(ByVal Progress As Integer)
If Me.InvokeRequired Then
Me.Invoke(New ProgressDelegate( _
AddressOf OnProgress _
), New Object() {Progress})
Else
Me.Button1.Text = Progress.ToString
End If
End Sub

Private Sub OnDone()
m_Thread = Nothing
End Sub

Class MyThread
Public Event Progress(ByVal Progress As Integer)
Public Event Done()

Private m_Thread As Thread

Public Sub Start()
m_Thread = New Thread(AddressOf ThreadStart)
m_Thread.Start()
End Sub

Private Sub ThreadStart()
Dim i As Integer
For i = 1 To 100
Thread.Sleep(100)
RaiseEvent Progress(i)
Next
RaiseEvent Done()
End Sub

End Class


Start the application and press the button.

If you've got any questions, don't hesitate to ask.
 
* "Shawn Regan said:
What is the best practice to show a window/form of some
animation while processing is going on in the back ground.

I want the user to see something while some processing is
taking place.

Progress Dialog (for C#, can be converted to VB.NET):

<http://www.codeproject.com/cs/miscctrl/progressdialog.asp>

Multithreading + Windows Forms:

<http://www.devx.com/dotnet/Article/11358>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
In a new project, add a button to the Form. Also add the following code:

Private m_Thread As MyThread

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

m_Thread = New MyThread
AddHandler m_Thread.Progress, AddressOf OnProgress
AddHandler m_Thread.Done, AddressOf OnDone
m_Thread.Start()
End Sub

Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)

Private Sub OnProgress(ByVal Progress As Integer)
If Me.InvokeRequired Then
Me.Invoke(New ProgressDelegate( _
AddressOf OnProgress _
), New Object() {Progress})
Else
Me.Button1.Text = Progress.ToString
End If
End Sub

Private Sub OnDone()
m_Thread = Nothing
End Sub

Class MyThread
Public Event Progress(ByVal Progress As Integer)
Public Event Done()

Private m_Thread As Thread

Public Sub Start()
m_Thread = New Thread(AddressOf ThreadStart)
m_Thread.Start()
End Sub

Private Sub ThreadStart()
Dim i As Integer
For i = 1 To 100
Thread.Sleep(100)
RaiseEvent Progress(i)
Next
RaiseEvent Done()
End Sub

End Class


Start the application and press the button.

If you've got any questions, don't hesitate to ask.

Very nice...
 
Hello,

What is the best practice to show a window/form of some
animation while processing is going on in the back ground.

I want the user to see something while some processing is
taking place.

TIA

You all ready got some exelent advice, but I'd thought I'd throw out an
additional resource for your consumption... This is part one of a 3
part article on Windows forms and threading. The code is in C#, but the
principals apply equally to VB.NET and the code is pretty trivial to
convert to VB.NET:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
 
Back
Top