Hey all, I'm having a problem with the following:
Private m_myDELEGATE As New myDELEGATE(Addr essOf
ReceivingServer Message_UIThrea d)
Delegate Sub myDELEGATE(ByVa l ReceivingServer Message As NetworkMessage)
Public Sub ReceivingServer Message(ByVal objNetworkMessa ge As NetworkMessage)
If (Me.InvokeRequi red) Then
Dim args() As Object = {objNetworkMess age}
Me.Invoke(m_myD ELEGATE, args)
Else
ReceivingServer Message_UIThrea d(objNetworkMes sage)
End If
End Sub
Basically I use this method to pass control from a worker thread back to the
UI Thread. It works fine if its a normal thread, but when I use a timer and
call this method after the timer elapses, then Me.InvokeRequir ed = False and
it treats it likes its already on the main thread, and thus when I get in
ReceivingServer Message_UIThrea d, I'm getting the all to familiar
"Cross-Thread operation not valid" error.
I thought Timers were just special cases of threads. What is going on
and/or what do I need to do to correct my problem?
Private m_myDELEGATE As New myDELEGATE(Addr essOf
ReceivingServer Message_UIThrea d)
Delegate Sub myDELEGATE(ByVa l ReceivingServer Message As NetworkMessage)
Public Sub ReceivingServer Message(ByVal objNetworkMessa ge As NetworkMessage)
If (Me.InvokeRequi red) Then
Dim args() As Object = {objNetworkMess age}
Me.Invoke(m_myD ELEGATE, args)
Else
ReceivingServer Message_UIThrea d(objNetworkMes sage)
End If
End Sub
Basically I use this method to pass control from a worker thread back to the
UI Thread. It works fine if its a normal thread, but when I use a timer and
call this method after the timer elapses, then Me.InvokeRequir ed = False and
it treats it likes its already on the main thread, and thus when I get in
ReceivingServer Message_UIThrea d, I'm getting the all to familiar
"Cross-Thread operation not valid" error.
I thought Timers were just special cases of threads. What is going on
and/or what do I need to do to correct my problem?
Comment