<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>COMmunism: Sharing your Apartment</title><link>http://blogs.msdn.com/marcmill/archive/2005/09/29/475465.aspx</link><description>The advent of neutral COM objects introduces the interesting consequence that your thread might have to share an apartment. This means that if you assume all asynchronous calls into your thread are on the same apartment, you probably have a subtle bug.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: COMmunism: Sharing your Apartment</title><link>http://blogs.msdn.com/marcmill/archive/2005/09/29/475465.aspx#478550</link><pubDate>Sat, 08 Oct 2005 15:45:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:478550</guid><dc:creator>Arno Schoedl</dc:creator><description>Hello Marc,&lt;br&gt;&lt;br&gt;CoGetCallContext and IContextCallback are virtually undocumented, so I am not sure whether they are a solution to my problem. I have a COM interface (on a non-creatable object) which gets handed to another process to be called in the MTA.&lt;br&gt;&lt;br&gt;But the interface gets sent to the other process by a call from my app's main STA. And marshalling the interface there would marshal it as STA. So I created a separate COM MTA worker thread, which does nothing else but marshalling interfaces whenever the STA needs to send a MTA-marshalled interface off to another process.&lt;br&gt;&lt;br&gt;It seems to work fine: the call-backs arrive on separate threads as they should. Unfortunately, the profiler says this frequent thread switching is very slow. Is there a better way?&lt;br&gt;&lt;br&gt;Thank you for your help,&lt;br&gt;&lt;br&gt;Arno</description></item><item><title>re: COMmunism: Sharing your Apartment</title><link>http://blogs.msdn.com/marcmill/archive/2005/09/29/475465.aspx#479018</link><pubDate>Mon, 10 Oct 2005 09:33:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:479018</guid><dc:creator>marcmill</dc:creator><description>Arno:&lt;br&gt;&lt;br&gt;The short answer is: I don't know.&lt;br&gt;&lt;br&gt;The long answer is: trying using the neutral apartment instead.  The context callback stuff is virtually undocumented, but the interface is very straightforward, except for the bit about the IID and method number: I just pass IID_IContextCallback and &amp;quot;3&amp;quot; to get default context.  Seems to work fine so far, and seems to be what other places in the Windows source code does (shh!).&lt;br&gt;&lt;br&gt;-marc</description></item><item><title>re: COMmunism: Sharing your Apartment</title><link>http://blogs.msdn.com/marcmill/archive/2005/09/29/475465.aspx#479076</link><pubDate>Mon, 10 Oct 2005 13:45:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:479076</guid><dc:creator>Arno Schoedl</dc:creator><description>Thanks for your reply. I am a little reluctant to create the object in the neutral apartment, because as far as I understand, I can only do this via a registry entry and CoCreateInstance, and the object is currently non-creatable. I tried the IContextCallback::ContextCallback route, but found that IID_IEnterActivityWithNoLock is nowhere defined:-(&lt;br&gt;&lt;br&gt;Arno</description></item></channel></rss>