Unexpected Event Behavior When Using VB6 with COM Interop (C#)
We are using a COM Interop (C#) to allow for a VB6 application to send data to a server. Once the server receives the data, the managed code will raise a DataSent event. This event is only fired after a correlation ID is returned to the original caller.
About 1% of the time, we've encountered VB6 executing the raised event before finishing the function that originally sent the data.
Using the following code:
' InteropTester.COMEvents is the C# object '
Dim WithEvents m_ManagedData as InteropTester.COMEvents
Private Sub send_data()
Set m_ManagedData = new COMEvents
Dim id as Integer
' send 5 to using the managed interop object '
id = m_ManagedData.SendData(5)
LogData "ID " & id & " was returned"
m_correlationIds.Add id
End Sub
Private Sub m_ManagedData_DataSent(ByVal sender as Variant, ByVal id as Integer)
LogData "Data was successfully sent to C#"
' check if the returned ID is in the m_correlationIds collection goes here开发者_Go百科'
End Sub
We can verify that the id is returned with a value when we call m_ManagedData.SendData(5)
, but the logs then show that the m_ManagedData_DataSent
is occasionally called before send_data
ends.
How is possible for VB6 to access the Message Loop to know that the DataSent
event was raised before exiting send_data()
? We are not calling DoEvents
and everything within VB6 is synchronous.
Thanks in advance for your help.
I get the feeling that the COM event is raised faster than the result of the method call being marshaled back to VB6. How much of a time difference are you seeing between the 2 calls to LogData
?
精彩评论