<?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>What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx</link><description>Somehow it seems like it&amp;rsquo;s been &amp;ldquo; Threading Models &amp;rdquo; week, another example of &amp;ldquo; Blogger synergy &amp;rdquo;. I wrote this up for internal distribution to my group about a year ago, and I&amp;rsquo;ve been waiting for a good time to post</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#122396</link><pubDate>Wed, 28 Apr 2004 21:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:122396</guid><dc:creator>Raymond Chen</dc:creator><description>There's also the &amp;quot;Main&amp;quot; threading model which everyone should avoid. It exists for backwards compatibility with people who don't know how threads work.</description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#122890</link><pubDate>Thu, 29 Apr 2004 12:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:122890</guid><dc:creator>Craig</dc:creator><description>And here's what happens in .NET when you totally forget to specify a threading model at all: &lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://staff.develop.com/candera/weblog2/PermaLink.aspx?guid=4c8cde3c-5c62-43f3-bfe0-61feceab8032"&gt;http://staff.develop.com/candera/weblog2/PermaLink.aspx?guid=4c8cde3c-5c62-43f3-bfe0-61feceab8032&lt;/a&gt;&lt;br&gt;&lt;br&gt;:p </description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#122993</link><pubDate>Thu, 29 Apr 2004 15:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:122993</guid><dc:creator>Larry Osterman</dc:creator><description>To be technical, in this case you forgot to call CoInitializeEx(NULL, COINIT_APARTMENTTHREADED).  The SHBrowseFolder API (I think that's the one) is documented as requiring that it run in an STA.  If you don't have the [STAThread] attribute on your thread process, the CLR initializes your thread in the MTA.&lt;br&gt;</description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#122995</link><pubDate>Thu, 29 Apr 2004 15:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:122995</guid><dc:creator>Larry Osterman</dc:creator><description>Found it - From the MSDN documentation on SHBrowseForFolder:&lt;br&gt;&lt;br&gt;You must initialize Component Object Model (COM) using CoInitializeEx with the COINIT_APARTMENTTHREADED flag set in the dwCoInit parameter prior to calling SHBrowseForFolder. You can also use CoInitialize or OleInitialize, which always use apartment threading.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#123406</link><pubDate>Thu, 29 Apr 2004 23:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123406</guid><dc:creator>Larry Osterman</dc:creator><description>At least one site (&lt;a target="_new" href="http://theserverside.net/news/thread.tss?thread_id=25595"&gt;http://theserverside.net/news/thread.tss?thread_id=25595&lt;/a&gt;) picked up on this post yesterday, which is cool (I love readers :).  But I'll be honest and say that I think their post's a smidge off topic.&lt;br&gt;&lt;br&gt;My article was intended to be a commentary about what happens from the side of a component author - which threading model should you chose and why, and not really as guidelines for when (or why) you should use the [STAThread] or [MTAThread] attributes on your managed code.  But clearly the [STAThread]/[MTAThread] info can be inferred from the text.&lt;br&gt;&lt;br&gt;By default, all CLR threads run in the MTA, you have to explicitly tag them as running in the STA.  Which means that if (like Craig) you're interacting with a component that can only work in an STA, you can get burned pretty badly.  And the worst thing is that it's not always obvious what the threading model of the component is, it's not always clearly documented, sometimes you need to dig into the registry.&lt;br&gt;</description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#123749</link><pubDate>Fri, 30 Apr 2004 12:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123749</guid><dc:creator>Craig</dc:creator><description>Agreed - while I've long since internalized the rules around threads apartments, the problem is that it's not immediately obvious when you're violating them. &lt;br&gt;&lt;br&gt;In my case, the most heinous thing was the fact that it *sort of* worked without [STAThread]. That made the failure mode very unfamiliar and hard to figure out. &lt;br&gt;&lt;br&gt;Sorry if I took your post off-track. It just reminded me of the most mysterious manifestation of apartment confusion I've encountered recently. </description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#123897</link><pubDate>Fri, 30 Apr 2004 15:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123897</guid><dc:creator>Larry Osterman</dc:creator><description>It didn't.  And I have no idea why on earth SHBrowseForFolder shouldn't work in the MTA - the apartment model restrictions are typically to protect components from being accessed from multiple threads simultaneously, which I wouldn't think happened in this case.&lt;br&gt;</description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#125178</link><pubDate>Mon, 03 May 2004 18:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:125178</guid><dc:creator>Craig</dc:creator><description>It's likely for one of two reasons: &lt;br&gt;&lt;br&gt;1) The SHBrowseForFolder stuff communicates asynchronously with a background thread via a message pump, assuming the thread affinity of the component will handle synchronization properly. &lt;br&gt;2) The component creates some other component in an STA and the resulting inter-apartment marshalling introduces the bug. &lt;br&gt;&lt;br&gt;I'm totally guessing, of course. </description></item><item><title>Links about COM threading models</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#129761</link><pubDate>Tue, 11 May 2004 17:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:129761</guid><dc:creator>The Old New Thing</dc:creator><description>Raymond makes other people discuss stuff so he doesn't have to.</description></item><item><title>Links about COM Interop and threading</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#129806</link><pubDate>Tue, 11 May 2004 18:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:129806</guid><dc:creator>Hirlpoo</dc:creator><description /></item><item><title>Links about COM Interop and threading</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#129822</link><pubDate>Tue, 11 May 2004 18:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:129822</guid><dc:creator>Hirlpoo</dc:creator><description /></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#130404</link><pubDate>Wed, 12 May 2004 11:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:130404</guid><dc:creator>Phil Jollans</dc:creator><description>Maybe someone can help my understanding with regard to firing events between threads.&lt;br&gt;&lt;br&gt;One scenario that I have often had is as follows:&lt;br&gt;&lt;br&gt;I have an ATL COM component doing some work and a user interface in VB6. In the ATL component, I start a worker thread and want to fire events which will be handled by the user interface component in VB6.&lt;br&gt;&lt;br&gt;In practice, I know that firing events from the worker thread leads to problems, so what I do is call an intermediate method within my object, which then fires the event. The intermediate method runs in the user interface thread and not in the worker thread.&lt;br&gt;&lt;br&gt;The question is, why do I need to do this? Why can't I fire an event from a worker thread which then runs in the user interface thread.&lt;br&gt;&lt;br&gt;Surely marshalling works on events in just the same manner as it works on other COM calls.&lt;br&gt;&lt;br&gt;Phil</description></item><item><title>New and Notable 55</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#130420</link><pubDate>Wed, 12 May 2004 15:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:130420</guid><dc:creator>Sam Gentile's Blog</dc:creator><description /></item><item><title>New and Notable 55</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#130535</link><pubDate>Wed, 12 May 2004 19:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:130535</guid><dc:creator>Sam Gentile's Blog</dc:creator><description /></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#132224</link><pubDate>Fri, 14 May 2004 20:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:132224</guid><dc:creator>Luke Stevens</dc:creator><description>As I understood it, the main point of the STA was to integrate the threading of COM components, especially GUI-oriented ActiveX controls, with the single-threaded message pump used for windows. Even in .NET this problem still lingers and you have to call Control.Invoke to effect a thread switch or risk erratic consequences. It's not about synchronizing access to a single object (COM+ has a separate option for that), but about synchronizing access to the entire apartment and all objects within. SHBrowseForFolder probably runs into problems only because of the windowing it tries to use. </description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#132228</link><pubDate>Fri, 14 May 2004 21:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:132228</guid><dc:creator>Larry Osterman</dc:creator><description>Actually Control.Invoke's there for a totally different reason that has absolutely nothing to do with .Net - it's to avoid a deadlock that's associated with the fact that Windows ties a window to the thread that created the window.  So messages that are sent to that window MUST be processed on the thread that owns the window.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#177679</link><pubDate>Thu, 08 Jul 2004 20:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:177679</guid><dc:creator>Brad Blankenship</dc:creator><description>I have looked in the registry, and the threading model shows as both.  Is there a way to test the com object to determine how it is acting?  The COM Object I am using is the Microsoft ActiveX Bridge to Java.&lt;br&gt;&lt;br&gt;I am having a bunch of serialization and I think it is from this.</description></item><item><title>re: What are these "Threading Models" and why do I care?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#178620</link><pubDate>Fri, 09 Jul 2004 18:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:178620</guid><dc:creator>Larry Osterman</dc:creator><description>Unfortunately, no. If you're in the debugger, step into a call - if it calls into the object, you're in the same apartment as the object, if it steps into some proxy code, you're in a different apartment.&lt;br&gt;</description></item><item><title>How does COM activation work anyway?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#241422</link><pubDate>Tue, 12 Oct 2004 23:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:241422</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description /></item><item><title>re: So what exactly IS COM anyway?</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#244078</link><pubDate>Mon, 18 Oct 2004 22:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:244078</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description /></item><item><title>Concurrency, part way too many2 - Concurrency and the Win32 API set</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#399876</link><pubDate>Mon, 21 Mar 2005 20:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:399876</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description /></item><item><title>The application called an interface that was marshalled for a different thread.</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#456346</link><pubDate>Thu, 25 Aug 2005 20:43:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:456346</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description>Another one from someone sending a comment:&lt;br&gt;&lt;br&gt;I came across your blog and was wondering if what to do...</description></item><item><title>Another year, another post</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#552075</link><pubDate>Wed, 15 Mar 2006 20:21:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:552075</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description>Well, this year I didn't miss the anniversary of my first blog post.&lt;br&gt;I still can't quite believe it's...</description></item><item><title>Building XML Web Services for Windows Embedded CE 6.0</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#5395351</link><pubDate>Thu, 11 Oct 2007 02:24:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5395351</guid><dc:creator>Windows Embedded Blog</dc:creator><description>&lt;p&gt;Building XML Web Services for Windows Embedded CE 6.0 Back in 2002 I wrote an article for MSDN that talked&lt;/p&gt;
</description></item><item><title>Building XML Web Services for Windows Embedded CE 6.0</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#5395496</link><pubDate>Thu, 11 Oct 2007 02:58:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5395496</guid><dc:creator>Noticias externas</dc:creator><description>&lt;p&gt;Building XML Web Services for Windows Embedded CE 6.0 Back in 2002 I wrote an article for MSDN that talked&lt;/p&gt;
</description></item><item><title>MSDN Blog Postings  &amp;raquo; Building XML Web Services for Windows Embedded CE 6.0</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#5395619</link><pubDate>Thu, 11 Oct 2007 03:20:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5395619</guid><dc:creator>MSDN Blog Postings  » Building XML Web Services for Windows Embedded CE 6.0</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://msdnrss.thecoderblogs.com/2007/10/10/building-xml-web-services-for-windows-embedded-ce-60/"&gt;http://msdnrss.thecoderblogs.com/2007/10/10/building-xml-web-services-for-windows-embedded-ce-60/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Larry Osterman s WebLog What are these Threading Models and why do |  Portable Greenhouse</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#9681142</link><pubDate>Mon, 01 Jun 2009 22:44:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9681142</guid><dc:creator> Larry Osterman s WebLog What are these Threading Models and why do |  Portable Greenhouse</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://portablegreenhousesite.info/story.php?id=9737"&gt;http://portablegreenhousesite.info/story.php?id=9737&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Larry Osterman s WebLog What are these Threading Models and why do | debt consolidator</title><link>http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx#9787928</link><pubDate>Fri, 19 Jun 2009 17:19:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9787928</guid><dc:creator> Larry Osterman s WebLog What are these Threading Models and why do | debt consolidator</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://mydebtconsolidator.info/story.php?id=1259"&gt;http://mydebtconsolidator.info/story.php?id=1259&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>