Unexpected Event Behavior When Using VB6 with COM Interop (C#)

Posted by Randal on Stack Overflow See other posts from Stack Overflow or by Randal
Published on 2010-03-26T15:01:23Z Indexed on 2010/03/26 15:03 UTC
Read the original article Hit count: 345

Filed under:
|
|
|

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'
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.

© Stack Overflow or respective owner

Related posts about vb6

Related posts about com