M
Mark Denardo
Hey all, I'm having a problem with the following:
Private m_myDELEGATE As New myDELEGATE(AddressOf
ReceivingServerMessage_UIThread)
Delegate Sub myDELEGATE(ByVal ReceivingServerMessage As NetworkMessage)
Public Sub ReceivingServerMessage(ByVal objNetworkMessage As NetworkMessage)
If (Me.InvokeRequired) Then
Dim args() As Object = {objNetworkMessage}
Me.Invoke(m_myDELEGATE, args)
Else
ReceivingServerMessage_UIThread(objNetworkMessage)
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.InvokeRequired = False and
it treats it likes its already on the main thread, and thus when I get in
ReceivingServerMessage_UIThread, 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(AddressOf
ReceivingServerMessage_UIThread)
Delegate Sub myDELEGATE(ByVal ReceivingServerMessage As NetworkMessage)
Public Sub ReceivingServerMessage(ByVal objNetworkMessage As NetworkMessage)
If (Me.InvokeRequired) Then
Dim args() As Object = {objNetworkMessage}
Me.Invoke(m_myDELEGATE, args)
Else
ReceivingServerMessage_UIThread(objNetworkMessage)
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.InvokeRequired = False and
it treats it likes its already on the main thread, and thus when I get in
ReceivingServerMessage_UIThread, 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?