I'm trying to have a class, which uses threads be able to raise events
to the form that created it. I've seen solutions around the net for
this, but I didn't really like their implementation. Most involve
passing the form into the class, or require a lot of coding. All I
really need to do is be able to have my thread call a function within
that class which runs on the same thread as the class. I've done this
from within forms, but can't figure out how to do it within a class
(see my comment below). How do I invoke the function from the thread
that the class is created on? I don't want the form to have to invoke
it. Any suggestions?
Public Class myClass
Dim myThread As Thread
Private client As Socket
Public Sub start()
myThread = New Thread(AddressO f threadFun)
myThread .Start()
End Sub
Private Sub threadFun()
raiseThisEvent( CLASS_EVENTS.ST ART)
End Sub
Delegate Sub thisEventDelega te(ByVal thisEvent As CLASS_EVENTS)
Public Sub raiseThisEvent( ByVal thisEvent As CLASS_EVENTS)
if thisEvent = CLASS_EVENTS.ST ART then
RaiseEvent onStart()
end if
End Sub
Public Sub raiseClassEvent (ByVal thisEvent As CLASS_EVENTS)
Dim passDelegate As New thisEventDelega te(AddressOf
raiseThisEvent)
' **** This is what I'd do if it were in a form, how do I do
the same within a class?? ****
Me.Invoke(passD elegate, thisEvent)
' ****
End Sub
end class
to the form that created it. I've seen solutions around the net for
this, but I didn't really like their implementation. Most involve
passing the form into the class, or require a lot of coding. All I
really need to do is be able to have my thread call a function within
that class which runs on the same thread as the class. I've done this
from within forms, but can't figure out how to do it within a class
(see my comment below). How do I invoke the function from the thread
that the class is created on? I don't want the form to have to invoke
it. Any suggestions?
Public Class myClass
Dim myThread As Thread
Private client As Socket
Public Sub start()
myThread = New Thread(AddressO f threadFun)
myThread .Start()
End Sub
Private Sub threadFun()
raiseThisEvent( CLASS_EVENTS.ST ART)
End Sub
Delegate Sub thisEventDelega te(ByVal thisEvent As CLASS_EVENTS)
Public Sub raiseThisEvent( ByVal thisEvent As CLASS_EVENTS)
if thisEvent = CLASS_EVENTS.ST ART then
RaiseEvent onStart()
end if
End Sub
Public Sub raiseClassEvent (ByVal thisEvent As CLASS_EVENTS)
Dim passDelegate As New thisEventDelega te(AddressOf
raiseThisEvent)
' **** This is what I'd do if it were in a form, how do I do
the same within a class?? ****
Me.Invoke(passD elegate, thisEvent)
' ****
End Sub
end class
Comment