I was doing some testing with COM Interop. I exported this test class:-
<ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(GetType(ICounterEvents))> _
Public Class Counter
Implements ICounter
Public Event CountTicked(ByVal current As Integer, ByVal max As Integer)
Public Sub StartCount(ByVal max As Integer) Implements ICounter.StartCount
ThreadPool.QueueUserWorkItem(Sub() Count(max))
End Sub
Private Sub Count(ByVal max As Integer)
For i = 1 To max
Dim x As Integer = i
'COM Seems to synchronize this automatically
RaiseEvent CountTicked(x, max)
Thread.Sleep(300)
Next
End Sub
End Class
I tested the above in VB6 and it works as is which is quite strange. Notice that Count would be called on a worker thread so the event raised therein should be raised on the worker thread. Yet in VB6 I am able to change a Label's caption from the event handler with no problems or glitches which I would not expect. If this were done from VB.Net, it would throw a cross thread exception. My question is, what is going on when the class is used from VB6 ? Does COM automatically raise the event on the UI thread in the VB6 app ? Or does VB6 not care about controls being altered from worker threads ?