You should check if InvokeRequired is set on the ISynchronizeInv oke
interfaced of your event sink before raising the event from a separate
thread. If this event sink requires synchronization , you'll need to call
Invoke instead. Here is some sample code of a OnTestEvent that implements
this.
Public Event TestEvent as EventHandler
Protected Overridable Sub OnTestEvent(ByV al sender As Object, ByVal args
As System.EventArg s)
If Not TestEventEvent Is Nothing Then
Dim singlecast As EventHandler
'Check each multi-cast delegate
For Each singlecast In TestEventEvent. GetInvocationLi st
Dim syncInvoke As System.Componen tModel.ISynchro nizeInvoke
If TypeOf singlecast.Targ et Is
System.Componen tModel.ISynchro nizeInvoke Then
syncInvoke = CType(singlecas t.Target,
System.Componen tModel.ISynchro nizeInvoke)
End If
If Not syncInvoke Is Nothing Then
If syncInvoke.Invo keRequired Then
syncInvoke.Invo ke(singlecast, New Object() {Me, New
EventArgs})
Else
singlecast(Me, Nothing)
End If
End If
Next
End If
End Sub
"Bob" wrote:
Hi,
Moving a project from .net 2003 -> 2005 Beta 2
Windows App. Main Window is start object.
Main window spawns a thread.
After doing some work this thread raises an interrupt.
The event carries a reference to the class that raised it plus an
instantiated, empty eventarg.
RaiseEvent LineStateChange (Me, e)
The 'RaiseEvent' errors in 2005 with Cross thread...
Any ideas on what is going on here?
Thanks
Bob