I have some COM objects that I create and run in threads in a .NET application. Streams are marked as Single Threaded Apartments and everything seems to be working. I understand that if these threads try to access COM objects from the main thread, then these objects will be automatically marshaled and serialized for me in .NET, so even in this case everything will be processed for me, everything is safe and neat, although it is possible a little slow.
My question is that everything is working fine, I am not pumping a cycle of messages in the STA flows that I create. I would prefer to avoid the message loop if I could, due to additional complications that it might cause (and possible loss of efficiency).
I read a bunch of tips on why a message loop is needed (mainly from the very useful Hans Passant), and I understand that a message loop gives a place in thread A, where another thread B may be requested, that the COM objects living on thread A can be marshaled and reproduced. If this is correct, then until no other threads request any of the COM objects in thread A, is Thread A safe in that it does not inflate the message loop? Or are there other cases where a message loop may also come into play?
Am I playing with fire here? And is there ever a case when you ask whether you play with fire, but you do not?
user12861 May 18 '12 at 14:02 2012-05-18 14:02
source share