<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Living .NET... </title><link>http://msmvps.com/blogs/manoj/default.aspx</link><description>Musings on .NET, and the like - Manoj G [MVP, Connected Systems Developer]</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/ManojG" type="application/rss+xml" /><item><title>Using Interception with Dependency Injection: EL 4.1 and Unity Spring 1.2 create new avenues</title><link>http://feedproxy.google.com/~r/ManojG/~3/ea81tWqW_PI/using-interception-with-dependency-injection-el-4-1-and-unity-spring-1-2-create-new-avenues.aspx</link><pubDate>Fri, 16 Jan 2009 09:50:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1662404</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=1662404</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2009/01/16/using-interception-with-dependency-injection-el-4-1-and-unity-spring-1-2-create-new-avenues.aspx#comments</comments><description>It is customary to conceive any large application to be composed of several logical layers. It is also a practice to reduce the coupling between the layers. Typically, one would create an interface for each class of each layer and they would be coupled...(&lt;a href="http://msmvps.com/blogs/manoj/archive/2009/01/16/using-interception-with-dependency-injection-el-4-1-and-unity-spring-1-2-create-new-avenues.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1662404" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Da9eUzF0dXdrfIlF7wiNeYShZXY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Da9eUzF0dXdrfIlF7wiNeYShZXY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Da9eUzF0dXdrfIlF7wiNeYShZXY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Da9eUzF0dXdrfIlF7wiNeYShZXY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/cpRmh3qiMyk" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://msmvps.com/blogs/manoj/archive/tags/EL/default.aspx">EL</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2009/01/16/using-interception-with-dependency-injection-el-4-1-and-unity-spring-1-2-create-new-avenues.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/cpRmh3qiMyk/using-interception-with-dependency-injection-el-4-1-and-unity-spring-1-2-create-new-avenues.aspx</feedburner:origLink></item><item><title>Best practices in Workflow Design - Part 2</title><link>http://feedproxy.google.com/~r/ManojG/~3/UrHZbjciDRo/best-practices-in-workflow-design-part-2.aspx</link><pubDate>Mon, 14 Jul 2008 22:36:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1641063</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=1641063</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2008/07/15/best-practices-in-workflow-design-part-2.aspx#comments</comments><description>Naming convention in Workflows Workflow activities should be named appropriately. As much as possible, they should reflect names form the business domain. For example, it wouldn&amp;rsquo;t appear good to have names like ifelseActivity1 or callExternalMethodActivity1...(&lt;a href="http://msmvps.com/blogs/manoj/archive/2008/07/15/best-practices-in-workflow-design-part-2.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1641063" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6Opq8hg1pEf_GuoyEQYWTi6ND5c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6Opq8hg1pEf_GuoyEQYWTi6ND5c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6Opq8hg1pEf_GuoyEQYWTi6ND5c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6Opq8hg1pEf_GuoyEQYWTi6ND5c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/Osb8qXqhn6U" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/WF/default.aspx">WF</category><category domain="http://msmvps.com/blogs/manoj/archive/tags/Best+Practices/default.aspx">Best Practices</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2008/07/15/best-practices-in-workflow-design-part-2.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/Osb8qXqhn6U/best-practices-in-workflow-design-part-2.aspx</feedburner:origLink></item><item><title>Best practices in Workflow Design - Part 1</title><link>http://feedproxy.google.com/~r/ManojG/~3/WePJkSO23R8/Best-practices-in-Workflow-Design-_2D00_-Part-1.aspx</link><pubDate>Sat, 12 Jul 2008 00:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1640637</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=1640637</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2008/07/12/Best-practices-in-Workflow-Design-_2D00_-Part-1.aspx#comments</comments><description>It&amp;rsquo;s been a awfully long time since I have published a blog entry, and it seems like the world of technology has changed quite a bit since! The hiatus is over now, and I would like to starting putting down some thoughts and experiences on my new...(&lt;a href="http://msmvps.com/blogs/manoj/archive/2008/07/12/Best-practices-in-Workflow-Design-_2D00_-Part-1.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1640637" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pyBis2ZHtQwXKjo0TIkFago-By8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pyBis2ZHtQwXKjo0TIkFago-By8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pyBis2ZHtQwXKjo0TIkFago-By8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pyBis2ZHtQwXKjo0TIkFago-By8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/caT00ZTkhuY" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/WF/default.aspx">WF</category><category domain="http://msmvps.com/blogs/manoj/archive/tags/Best+Practices/default.aspx">Best Practices</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2008/07/12/Best-practices-in-Workflow-Design-_2D00_-Part-1.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/caT00ZTkhuY/Best-practices-in-Workflow-Design-_2D00_-Part-1.aspx</feedburner:origLink></item><item><title>WCF - A Perspective</title><link>http://feedproxy.google.com/~r/ManojG/~3/TGt9u3lpmDg/wcf-a-perspective.aspx</link><pubDate>Sun, 14 Jan 2007 11:24:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:490539</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=490539</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2007/01/14/wcf-a-perspective.aspx#comments</comments><description>.NET 3.0 has been made available to all the developers recently. With it comes a set of new set of API, which are simply there to unleash the .NET developer’s potential to create the next wave of powerful applications. These API, formerly called WinFX...(&lt;a href="http://msmvps.com/blogs/manoj/archive/2007/01/14/wcf-a-perspective.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://msmvps.com/aggbug.aspx?PostID=490539" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9jtFPYHiOGsW_7Nr4XzR7-6Mgpo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9jtFPYHiOGsW_7Nr4XzR7-6Mgpo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9jtFPYHiOGsW_7Nr4XzR7-6Mgpo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9jtFPYHiOGsW_7Nr4XzR7-6Mgpo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/-NBbU4cFmdw" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+3.0/default.aspx">.NET 3.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2007/01/14/wcf-a-perspective.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/-NBbU4cFmdw/wcf-a-perspective.aspx</feedburner:origLink></item><item><title>Implementing Timeout &amp; Retry</title><link>http://feedproxy.google.com/~r/ManojG/~3/-sL2XqTrrD0/Implementing-Timeout-_2600_-Retry.aspx</link><pubDate>Wed, 01 Nov 2006 11:58:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:235323</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=235323</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2006/11/01/Implementing-Timeout-_2600_-Retry.aspx#comments</comments><description>I have come across several situations where I need some sort of Timeout functionality for a particular operation. At the same time, I also needed a provision for retrying the operation a few times before calling quits. I thought about a solution using...(&lt;a href="http://msmvps.com/blogs/manoj/archive/2006/11/01/Implementing-Timeout-_2600_-Retry.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://msmvps.com/aggbug.aspx?PostID=235323" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BG-zRf-KDbBR22WbRoZZHjw-fH4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BG-zRf-KDbBR22WbRoZZHjw-fH4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BG-zRf-KDbBR22WbRoZZHjw-fH4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BG-zRf-KDbBR22WbRoZZHjw-fH4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/5fIcFZOopP4" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2006/11/01/Implementing-Timeout-_2600_-Retry.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/5fIcFZOopP4/Implementing-Timeout-_2600_-Retry.aspx</feedburner:origLink></item><item><title>Predicates in Action</title><link>http://feedproxy.google.com/~r/ManojG/~3/_x2cYJEb17E/Predicates-in-Action.aspx</link><pubDate>Tue, 29 Aug 2006 07:12:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:110761</guid><dc:creator>Manoj G</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=110761</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2006/08/29/Predicates-in-Action.aspx#comments</comments><description>Get to know about one of the cool new things in .NET 2.0 - Predicates!...(&lt;a href="http://msmvps.com/blogs/manoj/archive/2006/08/29/Predicates-in-Action.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://msmvps.com/aggbug.aspx?PostID=110761" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Qc3h4JNcQoFHHrqgGXEy3jYLlI4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Qc3h4JNcQoFHHrqgGXEy3jYLlI4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Qc3h4JNcQoFHHrqgGXEy3jYLlI4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Qc3h4JNcQoFHHrqgGXEy3jYLlI4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/wB6L1pIUNCk" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2006/08/29/Predicates-in-Action.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/wB6L1pIUNCk/Predicates-in-Action.aspx</feedburner:origLink></item><item><title>Musings on Web 2.0 - Part 2</title><link>http://feedproxy.google.com/~r/ManojG/~3/_FC1TLnGp6k/Web20Part2Microformats.aspx</link><pubDate>Sun, 23 Jul 2006 20:41:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:105532</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=105532</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2006/07/24/Web20Part2Microformats.aspx#comments</comments><description>This post of my deals with the need for structured data on the web today, and the emergence of new ways of exposing structured data - RSS, ATOM and Microformats...(&lt;a href="http://msmvps.com/blogs/manoj/archive/2006/07/24/Web20Part2Microformats.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://msmvps.com/aggbug.aspx?PostID=105532" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rpa8dLTjBOPdC052QyPL4Hj0yYA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rpa8dLTjBOPdC052QyPL4Hj0yYA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rpa8dLTjBOPdC052QyPL4Hj0yYA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rpa8dLTjBOPdC052QyPL4Hj0yYA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/6XMRGZoHLcQ" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/Web+2.0/default.aspx">Web 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2006/07/24/Web20Part2Microformats.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/6XMRGZoHLcQ/Web20Part2Microformats.aspx</feedburner:origLink></item><item><title>Musings on Web 2.0</title><link>http://feedproxy.google.com/~r/ManojG/~3/2R3H67hd_m0/97505.aspx</link><pubDate>Sun, 28 May 2006 19:42:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:97505</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=97505</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2006/05/29/97505.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Web 2.0 – undoubtedly, is one of the most debated software buzzwords in the recent times. [The other term, in my opinion, which has attracted a lot of debate (and abuse) in the recent history is SOA]. To many, it is just about embracing new techniques, which are DHTML and JavaScript centric. But excavating the early manuscripts of Web 2.0 (like &lt;A href="http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html"&gt;Tim O’Reilly's canonical Web 2.0 article&lt;/A&gt;) reveals a bigger picture.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;So, what exactly is Web 2.0? Here’s another very brief perspective to add to thousand others already existing in different flavors. I would start by putting it this way (the world’s smallest definition of Web 2.0): A set of &lt;U&gt;&lt;STRONG&gt;new ideologies&lt;/STRONG&gt;&lt;/U&gt; combined with a set of &lt;U&gt;&lt;STRONG&gt;novel techniques&lt;/STRONG&gt;&lt;/U&gt; for building today’s web applications. Another definition could simply be – a new ecosystem of applications (or say “services”) built on the WWW platform.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;STRONG&gt;The new ideologies:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;1) The Web Platform&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Websites today are not just places where static information is presented, or which offer a single service (like e-mail, storage, forums etc). Websites today are platforms in their own right. They offer the capability to “compose” disparate applications to build a very powerful whole. The word “Mash-Up” is a popular term used to represent this ideology of mixing (or re-mixing) data and functionality. Now, part of this realization is capable by seeing our large world of applications as services, which can be consumed in non-proprietary ways. Not just SOAP, but plain old JavaScript itself is turning out to be that duct-tape technology making this possible. Live, Google and PageFlakes are great examples of the same.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;2) De-centralization of the Authority &amp;amp; Data&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Websites of the past era basically owned the content and its presentation entirely. With Web 2.0, the authority on the source of the data and its presentation shifts to the user. The website or web application basically provides a canvas which the user leverages to consume (and compose) services from disparate sources to meet their needs. As an example, you could cite msn.com (of the yester years) giving way to Live.com of today.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;3) Collaboration&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;This is new trend to surface in recent past. Websites today are opening the doors to the world to participate, contribute and collaborate. In this model, users directly contribute to the data/knowledge base of the website. The exemplar of this ideology is “Wiki”s, and Wikipedia, which is one of the most popular websites today. Tim O’Reilly’s article rightly calls this “Harnessing Collective Intelligence”.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;STRONG&gt;The Novel Techniques:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;HTTP, DHTML, JavaScript haven’t changed much in the recent times. But these days, you get to here a lot of new jargons popping all over the place, all of these based of these fundamental technologies. At the lead of this jargon parade is AJAX (Asynchronous JavaScript and XML). Some others in this list are Comet, JSON, etc. An extensive examination of these would reveal that these are nothing but simple tweaks and hacks to existing methodologies like XMLHTTP and JavaScript’s own &lt;EM&gt;eval&lt;/EM&gt; function. Therefore, I term these seemingly “new technologies” as novel techniques.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;New or otherwise, these techniques and ideologies definitely have resulted in new possibilities and opportunities for web application developers. We are seeing new revenue models which transcend the notion of simple buying and selling which we saw in the recent past. A new journey has just begun, it is time for us to get on the bus and be a part a long adventure!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=97505" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZsoBsYPWdZzkEB3S4omdbfg2cZ0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZsoBsYPWdZzkEB3S4omdbfg2cZ0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZsoBsYPWdZzkEB3S4omdbfg2cZ0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZsoBsYPWdZzkEB3S4omdbfg2cZ0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/cN8WPPJ8ygc" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/Web+2.0/default.aspx">Web 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2006/05/29/97505.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/cN8WPPJ8ygc/97505.aspx</feedburner:origLink></item><item><title>Tip: Debugging Windows Services</title><link>http://feedproxy.google.com/~r/ManojG/~3/NhqixH2xiRU/89042.aspx</link><pubDate>Mon, 03 Apr 2006 18:25:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:89042</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=89042</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2006/04/04/89042.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;The other day, I was watching the PDC presentations on WCF and one of them was on hosting WCF services by Steve Maine. Part of the presentation was about hosting Indigo on Windows services (or NT Services). One of the demos had a small and very interesting tip on debugging service startup, which I shall try to elaborate here. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;I always wondered how the service startup code could be debugged. There are two problems which you would face invariably. First of all, there is no process to which you can attach a debugger to start with. I have done stupid things in the past to step into startup code - by adding a Thread.Sleep in the OnStart method, assuming that this would give me enough time to attach the debugger to the newly started process. This isn’t very smart as you would hit the second problem – the Service Controller Manager (SCM) would time the service out way too soon. Not to worry much - there is any elegant solution to both these problems. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;You need not add a Thread.Sleep anymore – just add a Debugger.Break in your code. This isn’t new, but I simply hadn’t found a use for this before. This method is actually pretty useful if you want to conditionally attach the debugger in situations like this. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;The solution to the problem of the SCM timing out is a method in the ServiceBase class (System.ServiceProcess) that has been added in .NET 2.0. This method is the &lt;STRONG&gt;RequestAdditionalTime&lt;/STRONG&gt;, which takes a single parameter – the amount of time in milliseconds that the SCM has to wait additionally before pulling the plug on the service. Note that this method can only be called inside of OnStart, OnPause, OnContinue and OnStop (basically all the commands you can forward to the SCM). &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Neat!&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=89042" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-lmIPJswkJg-tHG9yIFdZG60Hls/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-lmIPJswkJg-tHG9yIFdZG60Hls/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-lmIPJswkJg-tHG9yIFdZG60Hls/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-lmIPJswkJg-tHG9yIFdZG60Hls/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/trEj3Sa9E9k" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2006/04/04/89042.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/trEj3Sa9E9k/89042.aspx</feedburner:origLink></item><item><title>Useful additions in .NET 2.0 -  Part 3: EventHandler&lt;TEventArgs&gt;</title><link>http://feedproxy.google.com/~r/ManojG/~3/kfjPlyUhFlA/80141.aspx</link><pubDate>Sun, 01 Jan 2006 19:28:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:80141</guid><dc:creator>Manoj G</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=80141</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2006/01/02/80141.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;If your .NET class needs to generate events, at a minimum, you typically do the following:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;1)&amp;nbsp;Create a new class which derived from EventArgs – the instance of this class would be used to communicate certain information to the event handler about the event itself. For example, CacheExpiryEventArgs.&lt;/FONT&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;2)&amp;nbsp;A new delegate type whose instance points to a method, the signature of which looks something like: &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public delegate void CacheExpiryEventHandler(object sender, CacheExpiryEventArgs e);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;3)&amp;nbsp;You declare an event which is associated with the delegate you created in (2). For example,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public event CacheExpiryEventHandler CacheExpired&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Now, for every event in your application, you invariably create as many delegate types. If you notice, each of those delegates differs only by the second argument of the event handler – the class representing the event arguments. Now, wouldn’t it be great if you had a generic delegate parameterized by the respective EventArgs argument. With generics in .NET 2.0, this is exactly what you get, in the form of &lt;STRONG&gt;EventHandler&amp;lt;TEventArgs&amp;gt;.&lt;/STRONG&gt; With this in place, our example now would look like:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public event EventHandler&amp;lt;CacheExpiryEventArgs&amp;gt; CacheExpired;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;This is definitely convenient, as it would reduce the number of delegates that are created in any application. Generics is a great addition in .NET 2.0, which not only gives you performance and strong-typing, but also certain productivity benefits like in this case, and for that matter Nullable&amp;lt;T&amp;gt;, List&amp;lt;T&amp;gt; and may such instances.&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=80141" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3NXAndmcdHJ_p3OFVHLgtNCDmJk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3NXAndmcdHJ_p3OFVHLgtNCDmJk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3NXAndmcdHJ_p3OFVHLgtNCDmJk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3NXAndmcdHJ_p3OFVHLgtNCDmJk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/zuljmLiu47U" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2006/01/02/80141.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/zuljmLiu47U/80141.aspx</feedburner:origLink></item><item><title>Useful additions to .NET 2.0 - Part 2: Nullable Types</title><link>http://feedproxy.google.com/~r/ManojG/~3/U__Sby5MUFk/76046.aspx</link><pubDate>Sun, 20 Nov 2005 07:14:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:76046</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=76046</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/11/20/76046.aspx#comments</comments><description>&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Nullable types,&amp;nbsp;put in simple terms can be thought of as a way of having nullable value types. Quite obviously, one of the largest applicability of this concept is that of database programming, where you can associate a null value with any datatype. Not too long ago, while coding the data access layer, I did quite a lot of magic value checks on values to see whether I had to associate a null value (DBNull.Value) to the corresponding database parameter. This included Guid.Empty, Int32.MinValue, DateTime.MinValue and so on. So, I had to create one helper method for all the types that needed such checks. The example for int is shown below:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;static&amp;nbsp;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;GetDbIntValue(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;int&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;val)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;if&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(val&amp;nbsp;==&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;int&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;.MinValue)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;DBNull.Value&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;FONT color=#400000&gt;val&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Now, this effort is not good in a lot of ways though it serves its purpose. This methodology would require a handshake between the Business Logic Layer (BLL) and the Data Access Layer (DAL) as to what values are acceptable and what are not. The problem is that there is no universally accepted&amp;nbsp;set for the same, and hence there would be semantic coupling&amp;nbsp;between the Biz and the DAL layers.&amp;nbsp;The handsome alternative to this situation would be to use Nullable types. Wherever you used magic values, replace them with the corresponding instances of Nullable&amp;lt;T&amp;gt;. Most typically, these would be in the data transfer objects (DTO). In the DAL,&amp;nbsp;we could now have a single helper function (in lieu of many in the earlier case), which looks something&amp;nbsp;like:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;static&amp;nbsp;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;GetDbValue&amp;lt;T&amp;gt;(Nullable&amp;lt;T&amp;gt;&amp;nbsp;val)&amp;nbsp;where&amp;nbsp;T&amp;nbsp;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;struct&amp;nbsp;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;if&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(val.HasValue)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;val.Value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;else&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;DBNull.Value;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;An adroit&amp;nbsp;developer might question&amp;nbsp;whether this helper nethod is really required. Why not have the IDbDataParameter instances 'infer' the right Dbtype from correponding nullable types. For example, you might have wanted this snippet to work without a hitch:&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Guid?&amp;nbsp;id&amp;nbsp;=&amp;nbsp;Guid.NewGuid();&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//Just&amp;nbsp;an&amp;nbsp;example&amp;nbsp;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;SqlCommand&amp;nbsp;cmd&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;SqlCommand("Select&amp;nbsp;*&amp;nbsp;from&amp;nbsp;Sample&amp;nbsp;where&amp;nbsp;id&amp;nbsp;=&amp;nbsp;@Id");&lt;BR&gt;cmd.Parameters.AddWithValue("@Id",&amp;nbsp;id);&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080&gt;But unfortunately, at this point of time, there is no conversions built in for nullable types and you would end up getting this exception message:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial color=#ff0000 size=2&gt;No mapping exists from object type System.Nullable`1[[System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;So, till there is support for Nullable types from System.Data (not sure why it should not be), you are better off using the simple helper listed earlier. &lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Before closing off, I would recommend that you read &lt;STRONG&gt;&lt;A href="http://msdn.microsoft.com/vcsharp/2005/overview/language/nullabletypes/"&gt;&lt;FONT color=#0000ff&gt;this article&lt;/FONT&gt;&lt;/A&gt;&lt;/STRONG&gt; to understand&amp;nbsp;all aspects of Nullable types.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color=#000080&gt;&lt;FONT size=2&gt;&lt;FONT face=Verdana&gt;Nullable types, unfortunately, is fully supported only in C# 2.0, and not in VB. In other words, VB does not have the additional language additions and compiler changes needed to support nullable types in a way C# does. However, nothing stops you from using Nullable&amp;lt;T&amp;gt; in VB; it is just that you would not have the shortcut notations like in C# (int? etc). You are encouraged to read &lt;STRONG&gt;&lt;A href="http://www.panopticoncentral.net/archive/2004/06/04/1180.aspx"&gt;&lt;FONT color=#0000ff&gt;this blog post&lt;/FONT&gt;&lt;/A&gt;&lt;/STRONG&gt; by Paul Vick, who explains this in detail.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=76046" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zpb8_bf6HzULrG3502al-mnk_Pw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zpb8_bf6HzULrG3502al-mnk_Pw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zpb8_bf6HzULrG3502al-mnk_Pw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zpb8_bf6HzULrG3502al-mnk_Pw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/qeNndazuF-A" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/11/20/76046.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/qeNndazuF-A/76046.aspx</feedburner:origLink></item><item><title>BackgroundWorker and SynchronizationContext</title><link>http://feedproxy.google.com/~r/ManojG/~3/xCoZWajzU1c/74120.aspx</link><pubDate>Thu, 03 Nov 2005 04:40:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:74120</guid><dc:creator>Manoj G</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=74120</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/11/03/74120.aspx#comments</comments><description>&lt;P style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;FONT color=#000080&gt;I have mentioned umpteen number of times earlier - .NET 2.0 comes with a wealth of new classes that have been added to the BCL. Today’s turn is of &lt;STRONG&gt;BackgroundWorker&lt;/STRONG&gt;. If you look at the available documentation (circa Beta 2), this is what you will find: &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;FONT color=#000080&gt;&lt;EM&gt;“Executes an operation on a separate thread”. You first reaction would be “Heck, what’s so “new” about that?”&lt;/EM&gt; Okay, so let’s spelunk into its properties and methods and try to find out. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 9.5pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 13.5pt"&gt;&lt;o:p&gt;&lt;FONT color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0&gt;

&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 6.15in; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" colSpan=2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Methods&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 1"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;RunWorkerAsync&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #e0dfe3; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Starts the designated method on a separate threadpool thread.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 2"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;CancelAsync&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #e0dfe3; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Requests the cancellation of the pending background operation&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 3"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 6.15in; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" colSpan=2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Events&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 4"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;ProgressedChanged&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #e0dfe3; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;This is called when the ReportProgress method is called&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 5"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;RunWorkerCompleted&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #e0dfe3; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Occurs when the background operation is completed&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 6; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;DoWork&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #e0dfe3; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: #e0dfe3; WIDTH: 221.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Occurs when the RunAsync method is called.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Again, after looking at these, you thoughts wouldn’t change – “&lt;I style="mso-bidi-font-style: normal"&gt;Still, what’s so great about the same? I had created similar helpers in .NET 1.1&lt;/I&gt;.”. &lt;/FONT&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Fine, let me tell what’s new. The very interesting aspect about the BackgroundWorker is the fact that RunWorkerCompleted and ProgressChanged event handlers would execute on the thread that created the BackgroundWorker object – most typically on a Windows form main thread (the thread on which the UI controls are created). Therefore, you now do not fall into a trap that you used to fall into earlier – updating a winform control on the wrong thread and facing unpredictable results. (Note that the DoWork method runs on a separate threadpool thread – do not update UI controls on that method) &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;So, you would now say: “&lt;I style="mso-bidi-font-style: normal"&gt;Cool, the BackgroundWorker probably has a reference to the &lt;STRONG&gt;ISynchronizeInvoke&lt;/STRONG&gt; object, and it would call &lt;STRONG&gt;Invoke &lt;/STRONG&gt;on it to dispatch the method on the right thread.&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;(System.Windows.Forms.Contrtol class implements the&lt;/I&gt; &lt;I style="mso-bidi-font-style: normal"&gt;ISynchronizeInvoke interface) &lt;/I&gt;”.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;If you look closely, the BackgroundWorker is actually agnostic of the environment it runs in. It could not even be a winform application, or even if it was, it does not really rely on ISynchronizeInvoke directly. So, how does this magic happen?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;With the help of the valuable services of Reflector, I came to know about a new class (a set of them actually) introduced in .NET 2.0, which &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;are responsible for this magic – &lt;STRONG&gt;SynchronizationContext&lt;/STRONG&gt;. Here’s what the documentation says:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 9.5pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 13.5pt"&gt;&lt;o:p&gt;&lt;FONT color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 9.5pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 13.5pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;FONT color=#000080&gt;“&lt;I style="mso-bidi-font-style: normal"&gt;Provides the basic functionality for propagating a synchronization context in various synchronization models. &lt;/I&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="FONT-SIZE: 8.5pt; mso-bidi-font-size: 12.0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;The purpose of the synchronization model implemented by this class is to allow the internal asynchronous/synchronization operations of the common language runtime (CLR) to behave properly with different synchronization models. This model also simplifies some of the requirements that managed applications have had to follow in order to work correctly under different synchronization environments&lt;/I&gt;”&lt;SPAN style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Can’t gather much from this explanation isn’t it? What is does mean perhaps is no more Control.Invoke. But it appears as if it is analogous to the thread’s Context object we had earlier, and a bit more specialized.&amp;nbsp;&lt;/FONT&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;By now, it would have rung another bell with you. As of .NET 2.0, in the case of Thread.Start method, the security context of the creating thread would be passed to the newly created thread. Guess what is behind this?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;I tried a hand at this new class, simple stuff actually. I created a thread&amp;nbsp;from the button click handler on a winform app and updated a control from the thread method (through anymymous method&amp;nbsp;in this case). This is the snippet &lt;/FONT&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;I tried:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;button1_Click(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;sender,&amp;nbsp;EventArgs&amp;nbsp;e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ctx&amp;nbsp;=&amp;nbsp;SynchronizationContext.Current;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;thanks&amp;nbsp;to&amp;nbsp;anonymous&amp;nbsp;methods,&amp;nbsp;everything&amp;nbsp;here&amp;nbsp;is&amp;nbsp;inline&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;thanks&amp;nbsp;to&amp;nbsp;me,&amp;nbsp;this&amp;nbsp;is&amp;nbsp;confusing&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;ThreadPool.QueueUserWorkItem(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;delegate&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;state)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;would&amp;nbsp;be&amp;nbsp;true&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Debug.WriteLine(Thread.CurrentThread.IsThreadPoolThread.ToString());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ctx.Send(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;delegate&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;someState)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;would&amp;nbsp;be&amp;nbsp;false&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;label1.Text&amp;nbsp;=&amp;nbsp;Thread.CurrentThread.IsThreadPoolThread.ToString();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;null&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;STRONG&gt;Send &lt;/STRONG&gt;is the method of the SynchronizationContext class&amp;nbsp;to dispatch the method on the right thread synchronously. To do the same asynchronously, we call &lt;STRONG&gt;Post. &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;STRONG&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Another interesting thing to note is - in .NET 2.0, if you update a control on the wrong thread, you get an InvalidOperationException. As of 1.1, there was no exception, but the result was unpredicatable.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;As you might have already guessed, there is not much documentation yet. But, unlike ContextBoundObject, ContextAttribute and other related classes, you might be seeing a lot of articles and proper documentation in the near future. At least, I shall spelunk a little more and come with an article of sorts.&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=74120" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0ynjRiS3bd8DRW7bH082LHeVos4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0ynjRiS3bd8DRW7bH082LHeVos4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0ynjRiS3bd8DRW7bH082LHeVos4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0ynjRiS3bd8DRW7bH082LHeVos4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/46hFyk5pWMU" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/11/03/74120.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/46hFyk5pWMU/74120.aspx</feedburner:origLink></item><item><title>Small, but useful additions in .NET 2.0 – Part 1</title><link>http://feedproxy.google.com/~r/ManojG/~3/jaaSH5Kqgws/73069.aspx</link><pubDate>Thu, 27 Oct 2005 04:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:73069</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=73069</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/10/27/73069.aspx#comments</comments><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;The BCL in .NET 2.0 has a plethora of small additions, which are not that visible, but are very useful. I’ll try to cover many of these in my subsequent posts. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;STRONG&gt;String.IsNullOrEmpty&lt;/STRONG&gt; is one such method. As the name would indicate, this method returns true if the string argument passed to this method is either null (nothing in VB) or empty.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;VB 2005 has some good additions too. Among others, I like the &lt;STRONG&gt;IsNot&lt;/STRONG&gt; operator. How much more did you want this operator after writing code like this:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;If Not obj Is Nothing&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;..&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Then&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Now,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;If &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;obj IsNot Nothing …looks much better.&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=73069" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yvcTDsR96_YRN-NxtskZAyUMl6A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yvcTDsR96_YRN-NxtskZAyUMl6A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yvcTDsR96_YRN-NxtskZAyUMl6A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yvcTDsR96_YRN-NxtskZAyUMl6A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/fNQNkTXTfxM" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/10/27/73069.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/fNQNkTXTfxM/73069.aspx</feedburner:origLink></item><item><title>A simple MSMQ Listener helper class</title><link>http://feedproxy.google.com/~r/ManojG/~3/2QuUfwuIKhY/70979.aspx</link><pubDate>Mon, 17 Oct 2005 01:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:70979</guid><dc:creator>Manoj G</dc:creator><slash:comments>10</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=70979</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/10/16/70979.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;MSMQ simply provides wonderful capabilities when it comes to building asynchronous messaging based applications. You typically run into situations where two applications exchange messages through a queue &amp;#8211; one application sends messages to a known MSMQ destination and the other application &amp;#8220;listens&amp;#8221; to this queue and picks messages up as and when they arrive. The application which listens usually is a windows service which either has a dedicated thread making a blocking call on the Receive method or uses a timer of sorts to periodically check the queue for new messages. Either ways, to maximize throughput, you need to write the queue-listener code in such a way that you can have multiple threads simultaneously processing different messages that arrive at the queue. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;MSMQ triggers provide one such solution where we can associate incoming messages to a COM component, based on certain rules, which can be application specific. MSMQ triggers are pretty powerful and also easy to administer. But there is one constraint, which has to do with the fact that only COM components are supported in this scheme, or in other words, message processors should be COM components. In a way, it isn&amp;#8217;t that bad a choice after all. You still can create a CCW for a managed class and register the trigger. But, somehow, I didn&amp;#8217;t like doing this.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;To circumvent this problem, I decided to write a C# helper class, which doesn&amp;#8217;t really do anything much, but helps realize a simple multithreaded job (message processing) dispatcher. The helper itself doesn&amp;#8217;t do any message processing as such; whenever a message arrives at a queue, it just fires an event (on a new thread pool thread) with the message contents being in the event arguments.&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;delegate&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageReceivedEventHandler(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;sender,&amp;nbsp;MessageEventArgs&amp;nbsp;args);&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;class&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MSMQListener&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;bool&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;_listen;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Type[]&amp;nbsp;_types;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageQueue&amp;nbsp;_queue;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;event&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageReceivedEventHandler&amp;nbsp;MessageReceived;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Type[]&amp;nbsp;FormatterTypes&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;get&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;_types;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;set&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&amp;nbsp;_types&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;value&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MSMQListener(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;string&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;queuePath)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageQueue(queuePath);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Start()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_listen&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;true&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;if&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(_types&amp;nbsp;!=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;null&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;&amp;amp;&amp;amp;&amp;nbsp;_types.Length&amp;nbsp;&amp;gt;&amp;nbsp;0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Using&amp;nbsp;only&amp;nbsp;the&amp;nbsp;XmlMessageFormatter.&amp;nbsp;You&amp;nbsp;can&amp;nbsp;use&amp;nbsp;other&amp;nbsp;formatters&amp;nbsp;as&amp;nbsp;well&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;_queue.Formatter&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;XmlMessageFormatter(_types);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue.PeekCompleted&amp;nbsp;+=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;PeekCompletedEventHandler(OnPeekCompleted);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue.ReceiveCompleted&amp;nbsp;+=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;ReceiveCompletedEventHandler(OnReceiveCompleted);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartListening();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Stop()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_listen&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;false&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue.PeekCompleted&amp;nbsp;-=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;PeekCompletedEventHandler(OnPeekCompleted);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue.ReceiveCompleted&amp;nbsp;-=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;ReceiveCompletedEventHandler(OnReceiveCompleted);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;StartListening()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;if&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(!_listen)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;The&amp;nbsp;MSMQ&amp;nbsp;class&amp;nbsp;does&amp;nbsp;not&amp;nbsp;have&amp;nbsp;a&amp;nbsp;BeginRecieve&amp;nbsp;method&amp;nbsp;that&amp;nbsp;can&amp;nbsp;take&amp;nbsp;in&amp;nbsp;a&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;MSMQ&amp;nbsp;transaction&amp;nbsp;object.&amp;nbsp;This&amp;nbsp;is&amp;nbsp;a&amp;nbsp;workaround&amp;nbsp;-&amp;nbsp;we&amp;nbsp;do&amp;nbsp;a&amp;nbsp;BeginPeek&amp;nbsp;and&amp;nbsp;then&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;recieve&amp;nbsp;the&amp;nbsp;message&amp;nbsp;synchronously&amp;nbsp;in&amp;nbsp;a&amp;nbsp;transaction.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Check&amp;nbsp;documentation&amp;nbsp;for&amp;nbsp;more&amp;nbsp;details&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;if&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(_queue.Transactional)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue.BeginPeek();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue.BeginReceive();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;OnPeekCompleted(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;sender,&amp;nbsp;PeekCompletedEventArgs&amp;nbsp;e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_queue.EndPeek(e.AsyncResult);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MessageQueueTransaction&amp;nbsp;trans&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageQueueTransaction();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Message&amp;nbsp;msg&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;null&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;try&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trans.Begin();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;msg&amp;nbsp;=&amp;nbsp;_queue.Receive(trans);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trans.Commit();&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartListening();&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FireRecieveEvent(msg.Body);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;catch&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trans.Abort();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;FireRecieveEvent(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;body)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;if&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(MessageReceived&amp;nbsp;!=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;null&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MessageReceived(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;this&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageEventArgs(body));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;OnReceiveCompleted(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;sender,&amp;nbsp;ReceiveCompletedEventArgs&amp;nbsp;e)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Message&amp;nbsp;msg&amp;nbsp;=&amp;nbsp;_queue.EndReceive(e.AsyncResult);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartListening();&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FireRecieveEvent(msg.Body);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;class&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageEventArgs&amp;nbsp;:&amp;nbsp;EventArgs&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;_messageBody;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageBody&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;get&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;_messageBody;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MessageEventArgs(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;object&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;body)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;_messageBody&amp;nbsp;=&amp;nbsp;body;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/SPAN&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;As you can see, the helper class is indeed simple. One thing to notice though is that, I switch to &lt;STRONG&gt;BeginPeek&lt;/STRONG&gt; if the queue is transactional. The reason behind this is there is no overload of the &lt;STRONG&gt;BeginRecieve&lt;/STRONG&gt; method that takes a &lt;STRONG&gt;MessageQueueTransaction&lt;/STRONG&gt; object and the MSDN documentation also explains the same. The workaround is to use BeginPeek and then do call &lt;STRONG&gt;Receive&lt;/STRONG&gt; (synchronous/blocking operation) in the EndPeek method. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;At this point of time, this class does not provide much control to the consumer. For instance, it does not allow you to set the maximum number of concurrent threads that can be processing messages - This class queues as many jobs as that supported by the .NET Thread pool. Also, I haven&amp;#8217;t tested this code in all scenarios &amp;#8211; I have not seen if this works well in the context of a distributed (DTC based) transaction. I shall update this version every now and then to make it more powerful and to work seamlessly in all scenarios.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=70979" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/K8hKFAlhMWg8WGxHdWHjiYdFrGM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/K8hKFAlhMWg8WGxHdWHjiYdFrGM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/K8hKFAlhMWg8WGxHdWHjiYdFrGM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/K8hKFAlhMWg8WGxHdWHjiYdFrGM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/IFkFFyS6c9k" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/10/16/70979.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/IFkFFyS6c9k/70979.aspx</feedburner:origLink></item><item><title>SetMaxThreads: A good addition to the ThreadPool class in 2.0</title><link>http://feedproxy.google.com/~r/ManojG/~3/zs6kCceHqOo/69175.aspx</link><pubDate>Thu, 06 Oct 2005 14:18:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:69175</guid><dc:creator>Manoj G</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=69175</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/10/06/69175.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;The &lt;STRONG&gt;ThreadPool&lt;/STRONG&gt; class is very handy to developers. You could queue a method to run on a separate thread and forget about it, without worrying about managing the thread object or about a possible thread explosion scenario. That&amp;#8217;s because the .NET ThreadPool keeps a tab on the number of executing threads, which I believe is a maximum of 25 per processor. This might sound just fine, but recently, I came across a situation where even 25 threads per processor looked expensive &amp;#8211; I needed to limit the count to something like 10. Unfortunately, the ThreadPool class didn&amp;#8217;t give me a method/property where I could set a thread count in the pool to something smaller.&amp;nbsp; I wasn&amp;#8217;t adept enough to host the CLR, where I could tweak this count. Instead, I decided to write a simplistic wrapper over the ThreadPool class, which basically did these things:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Keep a count on the number of active threads (which I wanted to limit in the first place)&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Maintain a queue to store requests is threads aren&amp;#8217;t available &lt;/FONT&gt;
&lt;LI&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;A timer implementation, where a thread periodically checks whether queued jobs can now be pushed to the thread pool &lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Quite obviously, this is a logical replica of the ThreadPool implementation itself, which is pretty wasteful. But that was until .NET Framework 1.1. In .NET 2.0, the ThreadPool class comes with this new method called &lt;STRONG&gt;SetMaxThreads&lt;/STRONG&gt; &amp;#8211; just what I craved for. You can use this to set the maximum number threads in the thread pool. There are two values to set here &amp;#8211; one for the worker threads (which is more relevant in my case), and one for IO Port completion (this is useful for asynchronous IO operations). &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Again, it is one's responsibility not to set an arbitrary high value of worker threads; Do I need to explain why?&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=69175" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/RqJm0bfpqaGvRrZJY2tTmBkqcAc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RqJm0bfpqaGvRrZJY2tTmBkqcAc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/RqJm0bfpqaGvRrZJY2tTmBkqcAc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RqJm0bfpqaGvRrZJY2tTmBkqcAc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/59k1LnPHTMQ" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/10/06/69175.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/59k1LnPHTMQ/69175.aspx</feedburner:origLink></item><item><title>DataSets - A journey from a boon, to a bane and back</title><link>http://feedproxy.google.com/~r/ManojG/~3/4dKFYyD12T0/DataSets-_2D00_-A-journey-from-a-boon_2C00_-to-a-bane-and-back.aspx</link><pubDate>Tue, 04 Oct 2005 09:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:68888</guid><dc:creator>Manoj G</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=68888</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/10/04/DataSets-_2D00_-A-journey-from-a-boon_2C00_-to-a-bane-and-back.aspx#comments</comments><description>&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font face="Verdana"&gt;&lt;font color="#000080"&gt;One of the biggest cribs about the DataSet in .NET 1.0 and 1.1 was its serialization performance. The DataSet, albeit providing a rich object model to work with data in a disconnected way, was a bane when it came to passing it across tiers of the application, typically in a remoting scenario. It turned out that in this scenario, the DataSet serialization glutted on bandwidth, memory and CPU cycles. Developers who were hell bent on using the DataSet eventually became the undisputed champions of object serialization, using wonky ways to serialize the dataset in an effort to make it optimal. Less nerdy developers adopted not so adventurous means like using custom collections and arrays, but sacrificing the high-fidelity object model of the DataSet in the process. &lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font color="#000080" face="Verdana"&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font face="Verdana"&gt;&lt;font color="#000080"&gt;Someone said that every complex problem has a simple solution, and .NET 2.0 is turning out to be an angel to this end. As you might have already guessed, the voice from the sky is in form of a new property of the DataSet (and surprise, DataTable too) called &lt;strong&gt;RemotingFormat&lt;/strong&gt;, which is an enumeration of type &lt;strong&gt;SerializationFormat&lt;/strong&gt; having two members &amp;ndash; Binary and Xml. Quite obviously, the default is Xml, to preserve backward compatibility. &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font color="#000080" face="Verdana"&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font face="Verdana"&gt;&lt;font color="#000080"&gt;Okay, I am digressing slightly here to note something interesting. The name of the property in discussion is RemotingFormat, not something like SerializationFormat or SerializedAs. I suppose, it is to enunciate two things:&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font face="Verdana"&gt;&lt;font color="#000080"&gt;DataSets (and now, even DataTable) implements &lt;strong&gt;IXmlSerializable&lt;/strong&gt;, which is what the XmlSerializer looks for when serializing objects in the web service scenario. So, setting the RemotingFormat property there would&amp;nbsp;be of no consequence, and it does not make sense there either. &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font face="Verdana"&gt;&lt;font color="#000080"&gt;Perhaps, DataSets are more apt for remoting scenarios, as compared to that of Web Services. This is not to say DataSets are deemed not usable in web services (as the implementation of IXmlSerializable would clarify). It is just that all the performance issues discussed earlier in this post would still apply in this case. &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="font-size:10pt;font-family:Arial;"&gt;&lt;font color="#000080" face="Verdana"&gt;Finally, I would urge you to read &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/10/CuttingEdge/"&gt;&lt;font color="#0000ff" face="Verdana"&gt;&lt;strong&gt;this excellent article&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;font color="#000080" face="Verdana"&gt; by Dino Esposito to get a better insight into this new feature and other improvements that have been added to the DataTable class as well. &lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=68888" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Hi8qmcy4u7JvSZCr2l8k9V6s3iM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hi8qmcy4u7JvSZCr2l8k9V6s3iM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Hi8qmcy4u7JvSZCr2l8k9V6s3iM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hi8qmcy4u7JvSZCr2l8k9V6s3iM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/gwiuJn2n6SI" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/10/04/DataSets-_2D00_-A-journey-from-a-boon_2C00_-to-a-bane-and-back.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/gwiuJn2n6SI/DataSets-_2D00_-A-journey-from-a-boon_2C00_-to-a-bane-and-back.aspx</feedburner:origLink></item><item><title>Patterns in .NET : Citing the Chain of Responsibility pattern</title><link>http://feedproxy.google.com/~r/ManojG/~3/5u3eKLmfpIY/68256.aspx</link><pubDate>Fri, 30 Sep 2005 03:24:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:68256</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=68256</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/09/29/68256.aspx#comments</comments><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;A href="http://www.dofactory.com/Patterns/PatternChain.aspx"&gt;&lt;FONT face=Verdana color=#0000ff&gt;&lt;STRONG&gt;Chain of Responsibility&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000080&gt; basically involves &amp;#8220;chaining&amp;#8221; a set of objects between a sender and receiver, where each object in the chain does some processing on the message that is sent between the sender and the receiver. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&lt;FONT face=Verdana color=#000080&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000080&gt;In the .NET Framework, one area where this pattern manifests is the Remoting infrastructure. In Remoting, a remote method call actually translates to a message exchange between the client and the server. When the message passes between client and the server object, it goes through a series of message sinks, which are objects which implement the &lt;STRONG&gt;IMessageSink&lt;/STRONG&gt; interface. Here&amp;#8217;s how the interface looks like (attributes have been elided for clarity):&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;interface&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;IMessageSink&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IMessageCtrl&amp;nbsp;AsyncProcessMessage(IMessage&amp;nbsp;msg,&amp;nbsp;IMessageSink&amp;nbsp;replySink);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IMessage&amp;nbsp;SyncProcessMessage(IMessage&amp;nbsp;msg);&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IMessageSink&amp;nbsp;NextSink&amp;nbsp;{&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;get&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;;&amp;nbsp;}&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;The important thing to notice here is that each message sink has a reference to the next sink in the chain. Each sink forwards the message to the next sink in the chain and the last sink to handle the message would be the &lt;STRONG&gt;StackBuilderSink&lt;/STRONG&gt;. The client and the server are actually unaware of the intermediate processing; the remote call appears no different from a local (intra-appdomain) call. This&amp;nbsp;scheme forms the basis of the Aspect framework built around the &lt;STRONG&gt;ContextBoundObject&lt;/STRONG&gt;. In fact, I suppose, all aspect frameworks would eventually use a realization of the Chain of Responsibility pattern.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT face=Verdana color=#000080 size=1&gt;&lt;EM&gt;PS: It has been quite a while since I posted on patterns topic and I apologize for that. &lt;/EM&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=68256" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uPbClCDB9zTzl-tFgF3zFvZIwv0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uPbClCDB9zTzl-tFgF3zFvZIwv0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uPbClCDB9zTzl-tFgF3zFvZIwv0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uPbClCDB9zTzl-tFgF3zFvZIwv0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/v5aHJqRY5eo" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/09/29/68256.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/v5aHJqRY5eo/68256.aspx</feedburner:origLink></item><item><title>Stopwatch your code!</title><link>http://feedproxy.google.com/~r/ManojG/~3/cqErO5J_lU0/68047.aspx</link><pubDate>Tue, 27 Sep 2005 13:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:68047</guid><dc:creator>Manoj G</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=68047</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/09/27/68047.aspx#comments</comments><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial"&gt;Timing managed code is one thing I do quite often. I guess measurement of the method level execution times is a common task for any application developer for that matter. I have used various methods for measurement; the worst of them all is using DateTime. DateTime simply does not give you that high resolution timing. The alterative was to use a couple of Win32 API called &lt;/SPAN&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT face=Verdana size=2&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;QueryPerformanceCounter &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT face=Verdana size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;and&lt;B&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt; QueryPerformanceFrequency. &lt;/SPAN&gt;&lt;/B&gt;If you have used MS Enterprise Library, you would see that the &lt;B&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Microsoft.Practices.EnterpriseLibrary.Logging.Tracing.Tracer&lt;/SPAN&gt;&lt;/B&gt; class uses these API for timing. There is a small catch in the implementation though. Since P/Invoke is involved here, every call would result in &lt;B&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;UnManagedCode&lt;/SPAN&gt;&lt;/B&gt; permission being demanded. The stack walk thus performed results in some loss in the resolution of the timing. Therefore, it is fair enough to mark the native method helpers with the &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;&lt;B&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;&lt;SPAN&gt;SuppressUnmanagedCodeSecurityAttribute. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;&lt;SPAN&gt;&lt;FONT color=#000080&gt;This attribute ensures that the permission demand happens only at link time (JIT compile time), and not for subsequent calls. If you are well aware of the security implications of this attribute usage, you are ready to go. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;Okay wait, don’t go far implementing all what I said earlier; &lt;B&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;System.Diagnostics.Stopwatch&lt;/SPAN&gt;&lt;/B&gt; in .NET 2.0 gives you just that. Here’s a snippet:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Stopwatch&amp;nbsp;watch&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;new&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Stopwatch();&lt;BR&gt;watch.Start();&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Some&amp;nbsp;operation&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;watch.Stop();&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;int&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;elapsedTime&amp;nbsp;=&amp;nbsp;watch.ElapsedMilliseconds;&lt;BR&gt;&lt;/DIV&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-weight: bold"&gt;&lt;FONT color=#000080&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000080&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial"&gt;The best part of about the Stopwatch class is that it intelligently uses a resolution based on whether the underlying hardware supports a high one or not (&lt;/SPAN&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;B&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;QueryPerformanceFrequency &lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;API returns true if high resolution is supported&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial"&gt;). If not supported, the Stopwatch reverts to that provided by DateTime. You can query the &lt;STRONG&gt;IsHighResolution&lt;/STRONG&gt; static property to find out whether high resolution is supported on your machine.&amp;nbsp;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=68047" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UlxLBrOM9D8OD9Q5gMbYfKUKwb8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UlxLBrOM9D8OD9Q5gMbYfKUKwb8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UlxLBrOM9D8OD9Q5gMbYfKUKwb8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UlxLBrOM9D8OD9Q5gMbYfKUKwb8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/PQKvPryIelg" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/09/27/68047.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/PQKvPryIelg/68047.aspx</feedburner:origLink></item><item><title>InternalsVisibleToAttribute - Friend Assemblies</title><link>http://feedproxy.google.com/~r/ManojG/~3/kVigWe7Wz60/67999.aspx</link><pubDate>Mon, 26 Sep 2005 16:24:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:67999</guid><dc:creator>Manoj G</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=67999</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/09/26/67999.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;You come across several situations where you need to develop a set of class libraries, say a framework of sorts, and there are several classes within certain assemblies which need to be marked as internal. You go ahead and mark them as internal, and then realize that there are other classes, within the framework, which are dependent on these marked classes, but exist in other assemblies. This is a problem, and you have no choice – you mark these classes as public and then document that the particular class should not be used directly from the code. You may think that this is a bad design, in a way, but there are no shortage of these in the .NET BCL. How often do you come across MSDN documentation which reads something like:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;"This class supports the .NET Framework infrastructure and is not intended to be used directly from your code."?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Ideally, these should have been internal classes, but you simply cannot have them that way. &lt;STRONG&gt;StrongNameIdentityPermission &lt;/STRONG&gt;provides an alternative, but it isn’t always practical.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;In .NET Framework 2.0, there exists a decent workaround to this problem. A new attribute called &lt;STRONG&gt;InternalsVisibleToAttribute&lt;/STRONG&gt; has been introduced, which when applied to an assembly indicates that all internal types in that assembly would be visible to another assembly, whose name is specified in the attribute constructor. In other words, that assembly becomes a friend assembly. The usage would be something like: &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;[assembly:InternalsVisibleToAttribute("MyFriendAssembly”)]&lt;BR&gt;Or (for a strong-named friend)&lt;BR&gt;[assembly:InternalsVisibleToAttribute("MyFriendAssembly, PublicKeyToken=45cb56a45e0a69a1")]&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Don’t get carried away, refer &lt;A href="http://msdn2.microsoft.com/library/0tke9fxk(en-us,vs.80).aspx"&gt;&lt;FONT color=#0000ff&gt;&lt;STRONG&gt;to this MSDN section&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/A&gt; to know more about the constraints and other considerations while using this attribute.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;Now, what could be the usage scenarios for this attribute? I have already explained one such scenario in the earlier sections of this post. Another case may be that of unit test assemblies. Typically, we keep unit tests in separate assemblies. Now, to be able to test all the internal classes/methods, it would be useful to gain visibility into them. So, we may declare the unit-test assembly as a friend of the actual assembly.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;[Digression: Adroit users of VS 2005 may quickly pounce upon the last use. VS 2005 unit testing framework provides reflection-based helpers which help you write tests against non-public members of a class. So, it’s left to you to decide which a better choice is]&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=67999" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CZqzdvtQD8WJBnq9ehpL9q6dzK0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CZqzdvtQD8WJBnq9ehpL9q6dzK0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CZqzdvtQD8WJBnq9ehpL9q6dzK0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CZqzdvtQD8WJBnq9ehpL9q6dzK0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/kA6CTzzTohw" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET+2.0/default.aspx">.NET 2.0</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/09/26/67999.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/kA6CTzzTohw/67999.aspx</feedburner:origLink></item><item><title>Manual ADO.NET Transactions and TLS</title><link>http://feedproxy.google.com/~r/ManojG/~3/dodVoDPQ5q0/66838.aspx</link><pubDate>Mon, 19 Sep 2005 00:24:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:66838</guid><dc:creator>Manoj G</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://msmvps.com/blogs/manoj/rsscomments.aspx?PostID=66838</wfw:commentRss><comments>http://msmvps.com/blogs/manoj/archive/2005/09/18/66838.aspx#comments</comments><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000080&gt;I have come across several business and data access layer components which have method overloads taking in SqlTransaction (or IDbTransaction) references. The need here is to facilitate ADO.NET manual transactions, where database operations scattered across several components would need to be enlisted under the same transaction. Let&amp;#8217;s assume for now that we do not want to avail the automatic transaction services of Enterprise Services or the DTC; performance being one reason, the unavoidable need to derive from System.EnterpriseServices.ServicedComponent being another. The obvious pain in the manual transaction scheme in our case is the leakage of ADO.NET objects (SqlTransaction) into the Business layer, which ideally, shouldn&amp;#8217;t be dealing with ADO.NET specific objects at all.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face=Verdana color=#000080&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000080&gt;So, what could be the solution to this problem? I thought &lt;STRONG&gt;TLS (Thread Local Storage)&lt;/STRONG&gt; could be put to good avail in this case. My idea involves the following steps:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="mso-spacerun: yes"&gt;1)&amp;nbsp;Create a helper class (call it TransactionUtils) with BeginTransaction, Commit and RollBack methods which do the work of opening and closing connections and storing transaction (SqlTransaction, for example) objects in the current thread&amp;#8217;s named data slot. This helper would be used by the business component which forms the root of the transaction.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="mso-spacerun: yes"&gt;2)&amp;nbsp;Change the data access helper (or the DAAB) to check the current thread&amp;#8217;s slot for a transaction object and use it if it exists (append the current transaction to to the command object).&amp;nbsp; You could consider creating overloads which are &amp;#8216;TLS aware&amp;#8217;.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT color=#000080&gt;&lt;FONT face=Verdana&gt;This is what TransactionHelper would look like:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face=Arial size=2&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face=Arial&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;
&lt;P style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;class&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;TransactionHelper&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;To&amp;nbsp;ensure&amp;nbsp;TransactionHelper&amp;nbsp;is&amp;nbsp;not&amp;nbsp;instantiated.&amp;nbsp;All&amp;nbsp;methods&amp;nbsp;are&amp;nbsp;static&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;TransactionHelper()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Name&amp;nbsp;of&amp;nbsp;the&amp;nbsp;TLS&amp;nbsp;data&amp;nbsp;slot.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;const&amp;nbsp;string&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;TLS_SLOT_NAME&amp;nbsp;=&amp;nbsp;"IDbTransactionDataSlot";&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;Returns&amp;nbsp;a&amp;nbsp;boolean&amp;nbsp;value&amp;nbsp;which&amp;nbsp;indicates&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // whether&amp;nbsp;current&amp;nbsp;thread&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;is&amp;nbsp;in&amp;nbsp;a&amp;nbsp;transactional&amp;nbsp;context&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;static&amp;nbsp;bool&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;IsInTransaction()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(GetTransactionFromContext()&amp;nbsp;!=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;null&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;Begins&amp;nbsp;an&amp;nbsp;ADO.NET&amp;nbsp;transaction&amp;nbsp;with&amp;nbsp;the&amp;nbsp;specified&amp;nbsp;isolation&amp;nbsp;level.&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;Creates&amp;nbsp;a&amp;nbsp;TLS&amp;nbsp;data&amp;nbsp;slot&amp;nbsp;where&amp;nbsp;the&amp;nbsp;transaction&amp;nbsp;object&amp;nbsp;would&amp;nbsp;be&amp;nbsp;stored&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;BeginTransaction(IsolationLevel&amp;nbsp;isolationLevel,&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;string&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;connectionString)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//To&amp;nbsp;clear&amp;nbsp;off&amp;nbsp;the&amp;nbsp;transaction&amp;nbsp;slot,&amp;nbsp;if&amp;nbsp;in&amp;nbsp;use&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;FreeResources(GetTransactionFromContext());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbConnection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;GetConnection(connectionString);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbTransaction&amp;nbsp;trans&amp;nbsp;=&amp;nbsp;conn.BeginTransaction(isolationLevel);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LocalDataStoreSlot&amp;nbsp;slot&amp;nbsp;=&amp;nbsp;Thread.AllocateNamedDataSlot(TLS_SLOT_NAME);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread.SetData(slot,&amp;nbsp;trans);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;Begins&amp;nbsp;an&amp;nbsp;ADO.NET&amp;nbsp;transaction.&amp;nbsp;Creates&amp;nbsp;a&amp;nbsp;TLS&amp;nbsp;data&amp;nbsp;slot&amp;nbsp;where&amp;nbsp;the&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;transaction&amp;nbsp;object&amp;nbsp;would&amp;nbsp;be&amp;nbsp;stored&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;BeginTransaction(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;string&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;connectionString)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//To&amp;nbsp;clear&amp;nbsp;off&amp;nbsp;the&amp;nbsp;transaction&amp;nbsp;slot,&amp;nbsp;if&amp;nbsp;in&amp;nbsp;use&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;FreeResources(GetTransactionFromContext());&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbConnection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;GetConnection(connectionString);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbTransaction&amp;nbsp;trans&amp;nbsp;=&amp;nbsp;conn.BeginTransaction();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LocalDataStoreSlot&amp;nbsp;slot&amp;nbsp;=&amp;nbsp;Thread.AllocateNamedDataSlot(TLS_SLOT_NAME);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread.SetData(slot,&amp;nbsp;trans);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;Commits&amp;nbsp;the&amp;nbsp;current&amp;nbsp;transaction&amp;nbsp;and&amp;nbsp;frees&amp;nbsp;the&amp;nbsp;TLS&amp;nbsp;data&amp;nbsp;slot&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Commit()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbTransaction&amp;nbsp;trans&amp;nbsp;=&amp;nbsp;GetTransactionFromContext();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbConnection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;trans.Connection;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trans.Commit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn.Dispose();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FreeResources(trans);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;///&amp;nbsp;&lt;SUMMARY&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;///&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;Rolls&amp;nbsp;back&amp;nbsp;the&amp;nbsp;current&amp;nbsp;transaction&amp;nbsp;and&amp;nbsp;frees&amp;nbsp;the&amp;nbsp;TLS&amp;nbsp;data&amp;nbsp;slot&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #808080; FONT-FAMILY: Courier New"&gt;///&amp;nbsp;&lt;/SUMMARY&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;static&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Rollback()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbTransaction&amp;nbsp;trans&amp;nbsp;=&amp;nbsp;GetTransactionFromContext();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbConnection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;trans.Connection;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trans.Rollback();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn.Dispose();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FreeResources(trans);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Gets&amp;nbsp;an&amp;nbsp;IDbTransaction&amp;nbsp;object&amp;nbsp;from&amp;nbsp;the&amp;nbsp;TLS&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;internal&amp;nbsp;static&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;IDbTransaction&amp;nbsp;GetTransactionFromContext()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LocalDataStoreSlot&amp;nbsp;slot&amp;nbsp;=&amp;nbsp;Thread.GetNamedDataSlot(TLS_SLOT_NAME);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;Thread.GetData(slot)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;as&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;IDbTransaction;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Disposes&amp;nbsp;the&amp;nbsp;transaction&amp;nbsp;and&amp;nbsp;clears&amp;nbsp;the&amp;nbsp;TLS&amp;nbsp;slot&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;static&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;FreeResources(IDbTransaction&amp;nbsp;trans)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;if&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;(trans&amp;nbsp;!=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;null&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;trans.Dispose();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread.FreeNamedDataSlot(TLS_SLOT_NAME);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Gets&amp;nbsp;a&amp;nbsp;connection&amp;nbsp;object&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;private&amp;nbsp;static&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;IDbConnection&amp;nbsp;GetConnection(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;string&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;connectionString)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IDbConnection&amp;nbsp;conn&amp;nbsp;=&amp;nbsp;SqlHelper.GetConnection(connectionString);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;conn.Open();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;return&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;conn;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080&gt;So, the snippet of a business component which uses the TransactionHelper would look something like:&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;
&lt;DIV style="BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px solid; BACKGROUND-COLOR: gainsboro"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;class&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;MyBizComp&lt;BR&gt;{&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;public&amp;nbsp;void&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;DoSomeOperation()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;try&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TransactionHelper.BeginTransaction(connectionString);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Call&amp;nbsp;other&amp;nbsp;biz&amp;nbsp;components,&amp;nbsp;they&amp;nbsp;would&amp;nbsp;get&amp;nbsp;enlisted&amp;nbsp;within&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;the&amp;nbsp;same&amp;nbsp;transaction&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;TransactionHelper.Commit();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;catch&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TransactionHelper.Rollback();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #0000ff; FONT-FAMILY: Courier New"&gt;finally&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #008000; FONT-FAMILY: Courier New"&gt;//&amp;nbsp;Cleanup&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Courier New"&gt;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080&gt;So, we have a solution here, which is not that elegant, but atleast, sheilds the business layer from the nuances of ADO.NET. Note that the assumption here is that all the other business components eventually call those methods in the data access layer which are context (TLS) aware.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080&gt;Two important things to note regarding this approach:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080&gt;1) The connection is kept open (behind the scenes) during the period between the BeginTran and Commit, and therefore during the execution of all the business components that are enlisted in a single transaction. So, it is imperative to keep transaction bracket as small as possible to improve concurrency. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana color=#000080&gt;2) This methodology does not work in a multithreaded scenario, where different components in the call chain happen to execute on different threads. Obviously, because&amp;nbsp;TLS is thread specific.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT face=Verdana color=#000080&gt;&lt;A href="http://www.idesign.net/idesign/uploads/Transactions%20-%20WinForms%20TransContext.zip"&gt;&lt;STRONG&gt;&lt;FONT color=#0000ff&gt;Another similar implementation&lt;/FONT&gt;&lt;/STRONG&gt; &lt;/A&gt;you may want to look into is the transaction helper in Juval Lowy&amp;#8217;s site, IDesign.Net, where you have a helper class which does something similar, but wraps Enterprise Services.&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000080&gt;Come .NET 2.0, &lt;STRONG&gt;System.Transactions &lt;/STRONG&gt;provides an elegant way to &amp;#8220;scope&amp;#8221; a transaction in the business layer. Not so surprisingly, the current transaction (Ambient transaction) is persisted in the TLS. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000080&gt;System.Transactions is one of the coolest new things in .NET 2.0 and will be the subject of another post altogether. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=66838" width="1" height="1"&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CayoM0vE4JzrLq3d1Nsa8jOK6nI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CayoM0vE4JzrLq3d1Nsa8jOK6nI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CayoM0vE4JzrLq3d1Nsa8jOK6nI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CayoM0vE4JzrLq3d1Nsa8jOK6nI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ManojGR/~4/JG5DwDh979M" height="1" width="1"/&gt;</description><category domain="http://msmvps.com/blogs/manoj/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://msmvps.com/blogs/manoj/archive/2005/09/18/66838.aspx</feedburner:origLink><feedburner:origLink>http://feedproxy.google.com/~r/ManojGR/~3/JG5DwDh979M/66838.aspx</feedburner:origLink></item></channel></rss>
