{"id":16153,"date":"2009-11-04T07:00:00","date_gmt":"2009-11-04T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/11\/04\/good-advice-comes-with-a-rationale-so-you-can-tell-when-it-becomes-bad-advice\/"},"modified":"2009-11-04T07:00:00","modified_gmt":"2009-11-04T07:00:00","slug":"good-advice-comes-with-a-rationale-so-you-can-tell-when-it-becomes-bad-advice","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20091104-00\/?p=16153","title":{"rendered":"Good advice comes with a rationale so you can tell when it becomes bad advice"},"content":{"rendered":"<p>A customer asked for guidance in software design:<\/p>\n<blockquote class=\"q\"><p> Is there an issue with creating and using COM objects from a UI thread which was initialized as STA? I have heard that it is a best practice to create and use COM objects on a background thread which is MTA. I would like to have some more information as to why. Any help? <\/p><\/blockquote>\n<p> (I still have trouble with the phrase <i>best practice<\/i>, especially when it is combined with the indefinite article: <i>a best practice<\/i>. It&#8217;s like asking &#8220;Where is a tallest building?&#8221;)\n Good advice comes with a rationale so you can tell when it becomes bad advice. If you don&#8217;t understanding why something should be done, then you&#8217;ve fallen into the trap of cargo cult programming, and you&#8217;ll keep doing it even when it&#8217;s no longer necessary or even becomes deleterious.\n In fact, you will find that if you try to follow this advice to the letter, most shell objects will stop working, because <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/04\/24\/8420242.aspx\"> shell objects tend to require an STA<\/a>. But in the absence of a rationale document or any other context, it&#8217;s unclear what the scope of the original advice was. Maybe it makes sense in context, but right now it&#8217;s just a statement with no discussion or rationale.\n When I asked the customer, &#8220;Can you provide the documents that provided this recommendation? Perhaps this &#8216;best practice&#8217; makes sense in context. Right now, it&#8217;s just a bare recommendation with no discussion or rationale.&#8221;<\/p>\n<p> The customer never wrote back. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer asked for guidance in software design: Is there an issue with creating and using COM objects from a UI thread which was initialized as STA? I have heard that it is a best practice to create and use COM objects on a background thread which is MTA. I would like to have some [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-16153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>A customer asked for guidance in software design: Is there an issue with creating and using COM objects from a UI thread which was initialized as STA? I have heard that it is a best practice to create and use COM objects on a background thread which is MTA. I would like to have some [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=16153"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16153\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=16153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=16153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=16153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}