Hi,
I thought Armin would send his sample himself.
This Armin made a while ago.
\\\By Armin Zingler
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
///
I hope this helps a little bit?
Cor
Rather than putting a progress bar on all of my forms to show progress
during time consuming tasks, I made a form called frmProgress with 2
controls, a Label and a ProgressBar. Suppose I expose 1 property --
prgValue (the Value of the ProgressBar); how do I use threading so that my
time consuming task will open and display frmProgress as well as continually
update prgValue (and display its progress), and then close frmProgress upon
completion? This seems a pretty mundane thing to do. Is there an example
somewhere?