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.