Hi
I think in common a class event is designed as three part.
1. the delegate function
2. the event of type with that delegate
3. a OnXXXX Function will which fired the event
So I think we can add the InvokeRequired code in the OnXXXX Function.
e.g.
Private Sub OnFilesFound(By Val Sender As Object, _
ByVal e As System.EventArg s)
If Me.InvokeRequir ed Then
Dim del As New UpdateUIFilesFo undDelegate( _
AddressOf Me.UpdateUIFile sFound)
Me.BeginInvoke( del
Else
Me.UpdateUIFile sFound()
End If
End Sub
Asynchronous Execution in Visual Basic .NET
http://msdn.microsoft.com/library/de...us/dv_vstechar
t/html/vbasync.asp
Also the SmartRaiseEvent you provided is somewhat a common method will will
raiseevent on all kind of event, so the compile time check will be missing,
as we have to use "ByVal args As Object()" similar declaration to pass
parameters.
Or I think we may have another idea that we can add a OnSafeXXXX fuction
will marshal the invoke call.
e.g.
Private Sub OnFilesFound(By Val Sender As Object, _
ByVal e As System.EventArg s)
RaiseEvent FilesFound(Send er,e)
End Sub
Private Sub OnSafeFilesFoun d(ByVal Sender As Object, _
ByVal e As System.EventArg s)
If Me.InvokeRequir ed Then
'Invoke the OnFilesFound here
'Since the Sender and EventArgs has passed the compiling time
check, we just has the raiseevent call running on the UI thread just as we
do in the single thread program.
End If
End Sub
If you still have any concern, please feel free to post here.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.