A
Ajak
Hi all,
I would like to write a class (Task) with a method to do some lengthy
process based
on several of the class properties. The method is running on different
thread.
During the execution of the method, the class is suppose to fire events such
as
ProgressChanged. And it raises Completed and Failed event on completion and
error
respectively.
The question is, how do I raise the event in the main thread (where the
class is instantiated)
without having to write the InvokeRequired checking for each controls I want
to update, say,
ProgressBar and Labels. In other words, how to fire the events that this
class exposes so
that at the receiving end of the event, I do not have to write the tedious
Invoke function to
access/alter its controls properties.
FYI, the class is not a control. Just a plain Class Library.
Below is the simplified class structure I did:-
Class Task
Private m_prop1 as integer
Private m_prop2 as integer
Public Event ProgressChanged(ByVal currentvalue as integer)
Public Event Completed()
Public Event Failed(ByVal errmessage as String)
Public Property Property1() As Integer
....
End Property
Public Property Property2() As Integer
....
End Property
Public Sub ProcessTask()
Dim t As New Thead(AdressOf DoWork)
t.Start()
End
Private Sub DoWork()
Do
... (do processing here)
... (fires ProgressChanged event during the processing - RaiseEvent
ProgressChanged(val))
Loop While ....
RaiseEvent Completed()
End Sub
End Class
Thanks in advance.
Razak.
I would like to write a class (Task) with a method to do some lengthy
process based
on several of the class properties. The method is running on different
thread.
During the execution of the method, the class is suppose to fire events such
as
ProgressChanged. And it raises Completed and Failed event on completion and
error
respectively.
The question is, how do I raise the event in the main thread (where the
class is instantiated)
without having to write the InvokeRequired checking for each controls I want
to update, say,
ProgressBar and Labels. In other words, how to fire the events that this
class exposes so
that at the receiving end of the event, I do not have to write the tedious
Invoke function to
access/alter its controls properties.
FYI, the class is not a control. Just a plain Class Library.
Below is the simplified class structure I did:-
Class Task
Private m_prop1 as integer
Private m_prop2 as integer
Public Event ProgressChanged(ByVal currentvalue as integer)
Public Event Completed()
Public Event Failed(ByVal errmessage as String)
Public Property Property1() As Integer
....
End Property
Public Property Property2() As Integer
....
End Property
Public Sub ProcessTask()
Dim t As New Thead(AdressOf DoWork)
t.Start()
End
Private Sub DoWork()
Do
... (do processing here)
... (fires ProgressChanged event during the processing - RaiseEvent
ProgressChanged(val))
Loop While ....
RaiseEvent Completed()
End Sub
End Class
Thanks in advance.
Razak.