I have created a .NET class that is exposed to COM, and used from a VB6 application. This .NET class runs a Task, which raises some events. It appears that these events are being raised in the main thread in the VB6 application, and it all just works. I am trying to understand exactly how this works though. Are the events being marshaled to the main thread somehow - either by .NET or COM? From what I have read, if an STA thread is being used, calls from outside that thread will marshaled using the Windows message queue. How does that apply when calling a .NET/COM object from VB6?
Asked
Active
Viewed 48 times
3
-
If you mean the .NET class uses `await`, then it's [normal](http://stackoverflow.com/q/17661428/11683) it comes from the same thread. – GSerg Oct 24 '16 at 15:22
-
No, the .NET class does not use await. It uses Task.Factory.StartNew, and then uses RaiseEvent to raise the event from within the task. – Jeff Oct 24 '16 at 15:55
-
1"It all just works" is very much the idea behind an STA thread. The VB6 program created that thread and subscribed the event on that thread. The built-in automagic that the COM infrastructure provides ensures that the event is fired on that thread to meet the STA requirements. Same basic mechanism as Control.Invoke() and Dispatcher.Invoke(), you don't have to help. – Hans Passant Oct 24 '16 at 19:06