<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>kevin Mocha - DotNet</title>
    <link>http://blog.ilovedoudou.com/</link>
    <description>Bookmarks collected from web.</description>
    <language>en-us</language>
    <copyright>Kevin Mocha</copyright>
    <lastBuildDate>Mon, 19 Jul 2010 22:10:55 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>lulustock@gmail.com</managingEditor>
    <webMaster>lulustock@gmail.com</webMaster>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=8163cafc-2f1d-4f04-ba99-2de260a3b25a</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,8163cafc-2f1d-4f04-ba99-2de260a3b25a.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,8163cafc-2f1d-4f04-ba99-2de260a3b25a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8163cafc-2f1d-4f04-ba99-2de260a3b25a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.codethinked.com/post/2010/01/25/NET-40-and-SystemThreadingTasks.aspx" href="http://www.codethinked.com/post/2010/01/25/NET-40-and-SystemThreadingTasks.aspx">http://www.codethinked.com/post/2010/01/25/NET-40-and-SystemThreadingTasks.aspx</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=8163cafc-2f1d-4f04-ba99-2de260a3b25a" />
      </body>
      <title>.NET 4.0 and System.Threading.Tasks</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,8163cafc-2f1d-4f04-ba99-2de260a3b25a.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,8163cafc-2f1d-4f04-ba99-2de260a3b25a.aspx</link>
      <pubDate>Mon, 19 Jul 2010 22:10:55 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://www.codethinked.com/post/2010/01/25/NET-40-and-SystemThreadingTasks.aspx" href="http://www.codethinked.com/post/2010/01/25/NET-40-and-SystemThreadingTasks.aspx"&gt;http://www.codethinked.com/post/2010/01/25/NET-40-and-SystemThreadingTasks.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=8163cafc-2f1d-4f04-ba99-2de260a3b25a" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,8163cafc-2f1d-4f04-ba99-2de260a3b25a.aspx</comments>
      <category>DotNet;DotNet / CSharp</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=aab5eadc-2adf-420f-8451-57e3fb984cad</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,aab5eadc-2adf-420f-8451-57e3fb984cad.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,aab5eadc-2adf-420f-8451-57e3fb984cad.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=aab5eadc-2adf-420f-8451-57e3fb984cad</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
dropdownstyle: dropdownlist<br />
autocompletemode: append<br />
autocompletesource: listtiems
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=aab5eadc-2adf-420f-8451-57e3fb984cad" />
      </body>
      <title>Windows Forms Combobox DropDownStyle</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,aab5eadc-2adf-420f-8451-57e3fb984cad.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,aab5eadc-2adf-420f-8451-57e3fb984cad.aspx</link>
      <pubDate>Mon, 28 Jun 2010 18:09:25 GMT</pubDate>
      <description>&lt;p&gt;
dropdownstyle: dropdownlist&lt;br&gt;
autocompletemode: append&lt;br&gt;
autocompletesource: listtiems
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=aab5eadc-2adf-420f-8451-57e3fb984cad" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,aab5eadc-2adf-420f-8451-57e3fb984cad.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://stevenharman.net/blog/archive/2008/04/29/hacking-visual-studio-to-use-more-than-2gigabytes-of-memory.aspx" href="http://stevenharman.net/blog/archive/2008/04/29/hacking-visual-studio-to-use-more-than-2gigabytes-of-memory.aspx">http://stevenharman.net/blog/archive/2008/04/29/hacking-visual-studio-to-use-more-than-2gigabytes-of-memory.aspx</a>
        </p>
        <p>
          <a title="http://confluence.jetbrains.net/display/ReSharper/OutOfMemoryException+Fix" href="http://confluence.jetbrains.net/display/ReSharper/OutOfMemoryException+Fix">http://confluence.jetbrains.net/display/ReSharper/OutOfMemoryException+Fix</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3" />
      </body>
      <title>OutOfMemoryException Fix</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3.aspx</link>
      <pubDate>Mon, 28 Jun 2010 14:40:20 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://stevenharman.net/blog/archive/2008/04/29/hacking-visual-studio-to-use-more-than-2gigabytes-of-memory.aspx" href="http://stevenharman.net/blog/archive/2008/04/29/hacking-visual-studio-to-use-more-than-2gigabytes-of-memory.aspx"&gt;http://stevenharman.net/blog/archive/2008/04/29/hacking-visual-studio-to-use-more-than-2gigabytes-of-memory.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://confluence.jetbrains.net/display/ReSharper/OutOfMemoryException+Fix" href="http://confluence.jetbrains.net/display/ReSharper/OutOfMemoryException+Fix"&gt;http://confluence.jetbrains.net/display/ReSharper/OutOfMemoryException+Fix&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,bd6622e5-ec4e-43e2-9437-f8b6d2d4bad3.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://msdn.microsoft.com/en-us/library/bb335710.aspx" href="http://msdn.microsoft.com/en-us/library/bb335710.aspx">http://msdn.microsoft.com/en-us/library/bb335710.aspx</a>
        </p>
        <pre class="csharpcode">
          <span class="rem">// Lambda expression as executable
code.</span> Func&lt;<span class="kwrd">int</span>, <span class="kwrd">bool</span>&gt;
deleg = i =&gt; i &lt; 5; <span class="rem">// Invoke the delegate and display the
output.</span> Console.WriteLine(<span class="str">"deleg(4) = {0}"</span>, deleg(4)); <span class="rem">//
Lambda expression as data in the form of an expression tree.</span> System.Linq.Expressions.Expression&lt;Func&lt;<span class="kwrd">int</span>, <span class="kwrd">bool</span>&gt;&gt;
expr = i =&gt; i &lt; 5; <span class="rem">// Compile the expression tree into executable
code.</span> Func&lt;<span class="kwrd">int</span>, <span class="kwrd">bool</span>&gt;
deleg2 = expr.Compile(); <span class="rem">// Invoke the method and print the output.</span> Console.WriteLine(<span class="str">"deleg2(4)
= {0}"</span>, deleg2(4)); <span class="rem">/* This code produces the following output:</span><span class="rem"></span><span class="rem"> deleg(4)
= True</span><span class="rem"> deleg2(4) = True</span><span class="rem"> */</span></pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7" />
      </body>
      <title>Expression Class</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7.aspx</link>
      <pubDate>Fri, 28 May 2010 19:18:01 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/bb335710.aspx" href="http://msdn.microsoft.com/en-us/library/bb335710.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb335710.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;            &lt;span class="rem"&gt;// Lambda expression as executable
code.&lt;/span&gt; Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;
deleg = i =&amp;gt; i &amp;lt; 5; &lt;span class="rem"&gt;// Invoke the delegate and display the
output.&lt;/span&gt; Console.WriteLine(&lt;span class="str"&gt;"deleg(4) = {0}"&lt;/span&gt;, deleg(4)); &lt;span class="rem"&gt;//
Lambda expression as data in the form of an expression tree.&lt;/span&gt; System.Linq.Expressions.Expression&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt;
expr = i =&amp;gt; i &amp;lt; 5; &lt;span class="rem"&gt;// Compile the expression tree into executable
code.&lt;/span&gt; Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;
deleg2 = expr.Compile(); &lt;span class="rem"&gt;// Invoke the method and print the output.&lt;/span&gt; Console.WriteLine(&lt;span class="str"&gt;"deleg2(4)
= {0}"&lt;/span&gt;, deleg2(4)); &lt;span class="rem"&gt;/* This code produces the following output:&lt;/span&gt; &lt;span class="rem"&gt;&lt;/span&gt; &lt;span class="rem"&gt; deleg(4)
= True&lt;/span&gt; &lt;span class="rem"&gt; deleg2(4) = True&lt;/span&gt; &lt;span class="rem"&gt; */&lt;/span&gt; &lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,a496fef0-b07d-4c77-a1aa-2e0aed7bb0f7.aspx</comments>
      <category>DotNet;DotNet / CSharp</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=6149d66a-6a8f-45ab-ae10-e88ca6e58a91</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,6149d66a-6a8f-45ab-ae10-e88ca6e58a91.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,6149d66a-6a8f-45ab-ae10-e88ca6e58a91.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6149d66a-6a8f-45ab-ae10-e88ca6e58a91</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <pre class="csharpcode">
          <span class="kwrd">public</span> IPrintableDisplayableDocument
CreateReport(BillSummaryReportData reportData) { Word2007ReportWriter writer = <span class="kwrd">new</span> Word2007ReportWriter(reportData,
ResourceTransform.BillSummaryReport); Word2007Document document = writer.CreateReport(); <span class="kwrd">using</span> (var
stream = <span class="kwrd">new</span> MemoryStream()) { stream.Write(document.Content,
0, document.Content.Length); <span class="rem">// insert bill summary rtf chunk</span> var
wordDoc = WordprocessingDocument.Open(stream, <span class="kwrd">true</span>); Stream
streamImportRtf = <span class="kwrd">new</span> MemoryStream(UTF8Encoding.Default.GetBytes(reportData.BillSummaryReportBody.BillSummary));
AlternativeFormatImportPart chunkRtf = wordDoc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Rtf, <span class="str">"BillSummaryRtfChunk"</span>);
chunkRtf.FeedData(streamImportRtf); wordDoc.Close(); document.Content = stream.ToArray();
} <span class="kwrd">return</span> document; }</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=6149d66a-6a8f-45ab-ae10-e88ca6e58a91" />
      </body>
      <title>Conversion (MemoryStream and Byte Array)</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,6149d66a-6a8f-45ab-ae10-e88ca6e58a91.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,6149d66a-6a8f-45ab-ae10-e88ca6e58a91.aspx</link>
      <pubDate>Fri, 28 May 2010 19:12:51 GMT</pubDate>
      <description>&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; IPrintableDisplayableDocument
CreateReport(BillSummaryReportData reportData) { Word2007ReportWriter writer = &lt;span class="kwrd"&gt;new&lt;/span&gt; Word2007ReportWriter(reportData,
ResourceTransform.BillSummaryReport); Word2007Document document = writer.CreateReport(); &lt;span class="kwrd"&gt;using&lt;/span&gt; (var
stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryStream()) { stream.Write(document.Content,
0, document.Content.Length); &lt;span class="rem"&gt;// insert bill summary rtf chunk&lt;/span&gt; var
wordDoc = WordprocessingDocument.Open(stream, &lt;span class="kwrd"&gt;true&lt;/span&gt;); Stream
streamImportRtf = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryStream(UTF8Encoding.Default.GetBytes(reportData.BillSummaryReportBody.BillSummary));
AlternativeFormatImportPart chunkRtf = wordDoc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Rtf, &lt;span class="str"&gt;"BillSummaryRtfChunk"&lt;/span&gt;);
chunkRtf.FeedData(streamImportRtf); wordDoc.Close(); document.Content = stream.ToArray();
} &lt;span class="kwrd"&gt;return&lt;/span&gt; document; }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=6149d66a-6a8f-45ab-ae10-e88ca6e58a91" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,6149d66a-6a8f-45ab-ae10-e88ca6e58a91.aspx</comments>
      <category>DotNet;DotNet / CSharp</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.c-sharpcorner.com/uploadfile/skarthikeyan/dynamiccreatingapplication06022005064351am/dynamiccreatingapplication.aspx" href="http://www.c-sharpcorner.com/uploadfile/skarthikeyan/dynamiccreatingapplication06022005064351am/dynamiccreatingapplication.aspx">http://www.c-sharpcorner.com/uploadfile/skarthikeyan/dynamiccreatingapplication06022005064351am/dynamiccreatingapplication.aspx</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0" />
      </body>
      <title>Dynamically creating Applications using System.CodeDom</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0.aspx</link>
      <pubDate>Thu, 27 May 2010 04:05:49 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://www.c-sharpcorner.com/uploadfile/skarthikeyan/dynamiccreatingapplication06022005064351am/dynamiccreatingapplication.aspx" href="http://www.c-sharpcorner.com/uploadfile/skarthikeyan/dynamiccreatingapplication06022005064351am/dynamiccreatingapplication.aspx"&gt;http://www.c-sharpcorner.com/uploadfile/skarthikeyan/dynamiccreatingapplication06022005064351am/dynamiccreatingapplication.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,45bf7ea2-19cd-48e9-ac05-ebaf4f0e68b0.aspx</comments>
      <category>DotNet;DotNet / CSharp</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=cfc1da56-36ad-489d-9bf3-dfc7d524bc31</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,cfc1da56-36ad-489d-9bf3-dfc7d524bc31.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,cfc1da56-36ad-489d-9bf3-dfc7d524bc31.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=cfc1da56-36ad-489d-9bf3-dfc7d524bc31</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx" href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx">http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx</a>
        </p>
        <p>
          <font size="2">If the operation raises an exception that your code does not handle,
the </font>
          <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx">
            <font size="2">BackgroundWorker</font>
          </a>
          <font size="2"> catches
the exception and passes it into the </font>
          <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.runworkercompleted.aspx">
            <font size="2">RunWorkerCompleted</font>
          </a>
          <font size="2"> event
handler, where it is exposed as the </font>
          <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.asynccompletedeventargs.error.aspx">
            <font size="2">Error</font>
          </a>
          <font size="2"> property
of </font>
          <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.runworkercompletedeventargs.aspx">
            <font size="2">System.ComponentModel.RunWorkerCompletedEventArgs</font>
          </a>
          <font size="2">.
If you are running under the Visual Studio debugger, the debugger will break at the
point in the DoWork event handler where the unhandled exception was raised. If you
have more than one </font>
          <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx">
            <font size="2">BackgroundWorker</font>
          </a>
          <font size="2">,
you should not reference any of them directly, as this would couple your DoWork event
handler to a specific instance of </font>
          <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx">
            <font size="2">BackgroundWorker</font>
          </a>
          <font size="2">.
Instead, you should access your </font>
          <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx">
            <font size="2">BackgroundWorker</font>
          </a>
          <font size="2"> by
casting the sender parameter in your DoWork event handler.</font>
        </p>
        <p>
          <a title="http://blogs.msdn.com/thottams/archive/2009/04/11/asynchronous-delegates-and-calback.aspx" href="http://blogs.msdn.com/thottams/archive/2009/04/11/asynchronous-delegates-and-calback.aspx">http://blogs.msdn.com/thottams/archive/2009/04/11/asynchronous-delegates-and-calback.aspx</a>
        </p>
        <p>
          <font size="2">When you do a BeginInvoke the delegate is invoked on a thread from
the thread pool and on completion the callback is also called on the same thread pool
thread. Now, any exceptions that is thrown on this thread cannot be caught by the
main thread and so will crash the process. If you want to handle the exception, then
you have to catch the expected exception in the callback and store it to some state
and rethrow the exception from the main thread so that the callers above you can handle
it gracefully.</font>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=cfc1da56-36ad-489d-9bf3-dfc7d524bc31" />
      </body>
      <title>Exceptions in .Net Threading</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,cfc1da56-36ad-489d-9bf3-dfc7d524bc31.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,cfc1da56-36ad-489d-9bf3-dfc7d524bc31.aspx</link>
      <pubDate>Wed, 14 Apr 2010 13:33:47 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx" href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.dowork.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;If the operation raises an exception that your code does not handle,
the &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx"&gt;&lt;font size="2"&gt;BackgroundWorker&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; catches
the exception and passes it into the &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.runworkercompleted.aspx"&gt;&lt;font size="2"&gt;RunWorkerCompleted&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; event
handler, where it is exposed as the &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.asynccompletedeventargs.error.aspx"&gt;&lt;font size="2"&gt;Error&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; property
of &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.runworkercompletedeventargs.aspx"&gt;&lt;font size="2"&gt;System.ComponentModel.RunWorkerCompletedEventArgs&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.
If you are running under the Visual Studio debugger, the debugger will break at the
point in the DoWork event handler where the unhandled exception was raised. If you
have more than one &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx"&gt;&lt;font size="2"&gt;BackgroundWorker&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;,
you should not reference any of them directly, as this would couple your DoWork event
handler to a specific instance of &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx"&gt;&lt;font size="2"&gt;BackgroundWorker&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.
Instead, you should access your &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx"&gt;&lt;font size="2"&gt;BackgroundWorker&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; by
casting the sender parameter in your DoWork event handler.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://blogs.msdn.com/thottams/archive/2009/04/11/asynchronous-delegates-and-calback.aspx" href="http://blogs.msdn.com/thottams/archive/2009/04/11/asynchronous-delegates-and-calback.aspx"&gt;http://blogs.msdn.com/thottams/archive/2009/04/11/asynchronous-delegates-and-calback.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;When you do a BeginInvoke the delegate is invoked on a thread from
the thread pool and on completion the callback is also called on the same thread pool
thread. Now, any exceptions that is thrown on this thread cannot be caught by the
main thread and so will crash the process. If you want to handle the exception, then
you have to catch the expected exception in the callback and store it to some state
and rethrow the exception from the main thread so that the callers above you can handle
it gracefully.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=cfc1da56-36ad-489d-9bf3-dfc7d524bc31" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,cfc1da56-36ad-489d-9bf3-dfc7d524bc31.aspx</comments>
      <category>DotNet;DotNet / CSharp</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=8e0b9d0d-915f-491d-9781-f4af3cf88ffb</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,8e0b9d0d-915f-491d-9781-f4af3cf88ffb.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,8e0b9d0d-915f-491d-9781-f4af3cf88ffb.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8e0b9d0d-915f-491d-9781-f4af3cf88ffb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.albahari.com/threading/part2.aspx" href="http://www.albahari.com/threading/part2.aspx">http://www.albahari.com/threading/part2.aspx</a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/CThreading_EDFE/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/CThreading_EDFE/image_thumb.png" width="956" height="710" />
          </a>
        </p>
        <p>
          <strong>Passing Data to a Thread</strong>
        </p>
        <p>
          <strong>
            <br />
          </strong>
          <br />
The easiest way to pass arguments to a thread’s target method is to execute a lambda<br />
expression that calls the method with the desired arguments:<br /><br />
static void Main()<br />
{<br />
Thread t = new Thread ( () =&gt; Print ("Hello from t!") );<br />
t.Start();<br />
}<br /><br />
static void Print (string message) { Console.WriteLine (message); }<br /><br />
With this approach, you can pass in any number of arguments to the method. You<br />
can even wrap the entire implementation in a multistatement lambda:<br /><br />
new Thread (() =&gt;<br />
{<br />
Console.WriteLine ("I'm running on another thread!");<br />
Console.WriteLine ("This is so easy!");<br />
}).Start();<br /><br />
You can do the same thing almost as easily in C# 2.0 with anonymous methods:<br /><br />
new Thread (delegate()<br />
{<br />
...<br />
}).Start();<br /><br />
Another technique is to pass an argument into Thread’s Start method: 
</p>
        <p>
  
</p>
        <p>
static void Main()<br />
{<br />
Thread t = new Thread (Print);<br />
t.Start ("Hello from t!");<br />
}<br />
static void Print (object messageObj)<br />
{<br />
string message = (string) messageObj; // We need to cast here<br />
Console.WriteLine (message);<br />
}<br /><br />
This works because Thread’s constructor is overloaded to accept either of two<br />
delegates:<br /><br />
public delegate void ThreadStart();<br />
public delegate void ParameterizedThreadStart (object obj);<br /><br />
The limitation of ParameterizedThreadStart is that it accepts <strong>only one argument</strong>.<br />
And because it’s of type object, it usually needs to be cast. 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>Foreground and Background Threads</strong>
        </p>
        <p>
  
</p>
        <p>
When a process terminates in this manner, any finally blocks in the execution stack<br />
of background threads are circumvented. This is a problem if your program employs<br />
finally (or using) blocks to perform cleanup work such as releasing resources or<br />
deleting temporary files. To avoid this, you can explicitly wait out such background<br />
threads upon exiting an application. There are two ways to accomplish this:<br /><br />
• If you’ve created the thread yourself, call Join on the thread.<br />
• If you’re on a pooled thread (see “Thread Pooling” on page 800) use an event<br />
wait handle (see “Signaling with Event Wait Handles” on page 832). 
</p>
        <p>
  
</p>
        <p>
          <strong>Thread Pooling</strong>
        </p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
There are a number of ways to enter the thread pool:<br />
• Via the Task Parallel Library or PLINQ (from Framework 4.0)<br />
• By calling ThreadPool.QueueUserWorkItem<br />
• Via asynchronous delegates<br />
• Via BackgroundWorker 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
Here’s how you start a worker task via an asynchronous delegate:<br />
1. Instantiate a delegate targeting the method you want to run in parallel (typically<br />
one of the predefined Func delegates).<br />
2. Call BeginInvoke on the delegate, saving its IAsyncResult return value.<br />
BeginInvoke returns immediately to the caller. You can then perform other activities<br />
while the pooled thread is working.<br />
3. When you need the results, call EndInvoke on the delegate, passing in the saved<br />
IAsyncResult object. 
</p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
Don’t confuse asynchronous delegates with asynchronous<br />
methods (methods starting with Begin or End, such as<br />
File.BeginRead/File.EndRead). Asynchronous methods follow<br />
a similar protocol outwardly, but they exist to solve a much<br />
more difficult problem, which we describe in Chapter 23. 
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font size="2">Synchronization</font>
          </strong>
        </p>
        <p>
  
</p>
        <p>
          <strong>Nonblocking Synchronization</strong>
        </p>
        <p>
  
</p>
        <p>
The following implicitly generate full fences:<br />
• C#’s lock statement (Monitor.Enter/Monitor.Exit)<br />
• All methods on the Interlocked class (we’ll cover these soon)<br />
• Asynchronous callbacks that use the thread pool—these include asynchronous delegates,
APM callbacks (Chapter 23), and Task continuations (Chapter 22)<br />
• Setting and waiting on a signaling construct<br />
• Anything that relies on signaling, such as starting or waiting on a Task 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>Memory barriers and locking<br /></strong>
        </p>
        <p>
C#'s <tt>lock</tt><a name="call to"></a> statement is in fact a syntactic shortcut
for a call to the methods <tt>Monitor.Enter</tt> and <tt>Monitor.Exit</tt>, with a <tt>try</tt>-<tt>finally</tt> block.
Here's what's actually happening within the <tt>Go</tt> method of the preceding example:
</p>
        <pre>Monitor.Enter (locker);
try
{
  if (val2 != 0) Console.WriteLine (val1 / val2);
  val2 = 0;
}
finally { Monitor.Exit (locker); </pre>
        <p>
As we said earlier, Monitor.Enter and Monitor.Exit both generate full fences. So if<br />
we ignore a lock’s mutual exclusion guarantee, we could say that this:<br /><br />
lock (someField) { ... }<br /><br />
is equivalent to this:<br /><br />
Thread.MemoryBarrier(); { ... } Thread.MemoryBarrier();
</p>
        <p>
A <tt><strong><font size="2">Mutex</font></strong></tt> is like a C# <tt>lock</tt><a name="multiple processes"></a>,
but it can work across multiple processes. In other words, <tt>Mutex</tt> can be computer-wide
as well as application-wide.<br /></p>
        <p>
With a <tt>Mutex</tt> class, you call the <tt>WaitOne</tt> method to lock and <tt>ReleaseMutex</tt> to
unlock. Just as with the <tt>lock</tt> statement, a <tt>Mutex</tt><a name="obtained it"></a> can
be released only from the same thread that obtained it.<br />
A common use for a cross-process <tt>Mutex</tt><a name="of a"></a> is to ensure that
only one instance of a program can run at a time. 
</p>
        <p>
  
</p>
        <p>
A <tt><font size="2"><strong>Semaphore</strong></font></tt><a name="Once it"></a> is
like a nightclub: it has a certain capacity, enforced by a bouncer. Once it's full,
no more people can enter and a queue builds up outside. Then, for each person that
leaves, one person enters from the head of the queue. The constructor requires a minimum
of two arguments: the number of places currently available in the nightclub and the
club's total capacity.<br /><a name="IDX-CHP-19-3537"></a></p>
        <p>
          <br />
A <tt>Semaphore</tt><a name="of one"></a> with a capacity of one is similar to a <tt>Mutex</tt> or <tt>lock</tt><a name="the"></a>,
except that the <tt><strong>Semaphore</strong></tt><a name="has no"></a><strong> has
no "owner"—it's <i>thread-agnostic</i></strong><a name="can call"></a><strong>.</strong> Any
thread can call <tt>Release</tt><a name="a"></a> on a <tt>Semaphore</tt>, whereas
with <tt>Mutex</tt> and <tt>lock</tt>, only the thread that obtained the lock can
release it. 
</p>
        <p>
          <a name="from executing">
          </a>
          <br />
Semaphores can be useful in <strong>limiting concurrency</strong>—preventing too many
threads from executing a particular piece of code at once. In the following example,
five threads try to enter a nightclub that allows only three threads in at once: 
</p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
  
</p>
        <p>
          <strong>Interlocked<br /></strong>
        </p>
        <p>
Interlocked.Increment (ref _sum); 
<br />
Interlocked.Decrement (ref _sum); 
</p>
        <p>
  
</p>
        <p>
Interlocked’s mathematical operations are restricted to Increment, Decrement, and
Add. 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>Signaling with Event Wait Handles</strong>
        </p>
        <p>
          <strong>
          </strong>  
</p>
        <pre class="csharpcode">
          <span class="kwrd">class</span> BasicWaitHandle { <span class="kwrd">static</span> EventWaitHandle
wh = <span class="kwrd">new</span> AutoResetEvent (<span class="kwrd">false</span>); <span class="kwrd">static</span><span class="kwrd">void</span> Main(
) { <span class="kwrd">new</span> Thread (Waiter).Start( ); Thread.Sleep (1000); <span class="rem">//
Pause for a second...</span> wh.Set( ); <span class="rem">// Wake up the Waiter.</span> } <span class="kwrd">static</span><span class="kwrd">void</span> Waiter(
) { Console.WriteLine (<span class="str">"Waiting..."</span>); wh.WaitOne( ); <span class="rem">//
Wait for notification</span> Console.WriteLine (<span class="str">"Notified"</span>);
} } </pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
          <strong>Thread.Interrupt and Abort</strong>
        </p>
        <p>
Calling <tt>Interrupt</tt> on a blocked thread forcibly releases it, throwing a <tt>ThreadInterruptedException<br /></tt>Interrupting a thread does not cause the thread to end, unless the <tt>ThreadInterruptedException</tt> is
unhandled.
</p>
        <p>
The big difference between <tt>Interrupt</tt> and <tt>Abort</tt><a name="is not"></a> is
what happens when it's called on a thread that is not blocked. Whereas <tt>Interrupt</tt><a name="doing anything"></a> waits
until the thread next blocks before doing anything, <tt>Abort</tt><a name="This is"></a> throws
an exception on the thread right where it's executing (unmanaged code excepted). This
is a problem because .NET Framework code might be aborted; code that is not abort-safe.
This rules out using <tt>Abort</tt><a name="nontrivial context"></a> in almost any
nontrivial context. 
</p>
        <p>
  
</p>
        <p>
          <a name="a pattern">
          </a>An alternative to aborting another thread is to implement
a pattern whereby the worker periodically checks a <tt>cancel</tt> flag, exiting if
the flag is <tt>true</tt><a name="the flag"></a>. To abort, the instigator simply
sets the flag, and then waits for the worker to comply. 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>BackgroundWorker<br /></strong>
        </p>
        <p>
          <tt>BackgroundWorker</tt>
          <a name="is a">
          </a> is a helper class in the <tt>System.ComponentModel</tt><a name="managing a"></a> namespace
for managing a worker thread. It provides the following features:<a name="IDX-CHP-19-3642"></a><a name="IDX-CHP-19-3643"></a><a name="IDX-CHP-19-3644"></a><a name="IDX-CHP-19-3645"></a><a name="IDX-CHP-19-3646"></a><a name="IDX-CHP-19-3647"></a></p>
        <ul>
          <li>
            <p>
A <tt>cancel</tt><a name="for signaling"></a> flag for signaling a worker to end without
using <tt>Abort</tt></p>
          </li>
          <li>
            <p>
A standard protocol for reporting progress, completion, and cancellation
</p>
          </li>
          <li>
            <p>
An implementation of <tt>IComponent</tt> allowing it be sited in Visual Studio's designer
</p>
          </li>
          <li>
            <p>
Exception handling on the worker thread
</p>
          </li>
          <li>
            <p>
              <a name="in response">
              </a>The ability to update Windows Forms or WPF controls in response
to worker progress or completion
</p>
          </li>
        </ul>
        <pre class="csharpcode">    bw = <span class="kwrd">new</span> BackgroundWorker( );
bw.WorkerReportsProgress = <span class="kwrd">true</span>; bw.WorkerSupportsCancellation
= <span class="kwrd">true</span>; bw.DoWork += bw_DoWork; bw.ProgressChanged += bw_ProgressChanged;
bw.RunWorkerCompleted += bw_RunWorkerCompleted; bw.<font color="#ff0000">RunWorkerAsync </font>(<span class="str">"Hello
to worker"</span>); <strong>ReadWRiterLockSlim</strong></pre>
        <p>
          <a name="basic kinds">
          </a>With both classes, there are two basic kinds of lock—a read
lock and a write lock: 
</p>
        <ul>
          <li>
            <p>
A write lock is universally exclusive.
</p>
          </li>
          <li>
            <p>
A read lock is compatible with other read locks.
</p>
          </li>
        </ul>
        <p>
          <a name="threads trying">
          </a>
          <font color="#0080ff">So, a thread holding a write lock
blocks all other threads trying to obtain a read or</font>
          <a name="holds a">
          </a>
          <font color="#0080ff"> write
lock (and vice versa). But if no thread holds a write lock, any number of threads
may concurrently obtain a read lock.</font>
        </p>
        <p>
          <tt>ReaderWriterLockSlim</tt> defines the following methods for obtaining and releasing
read/write locks:
</p>
        <pre>public void EnterReadLock(  );
public void ExitReadLock(  );
public void EnterWriteLock(  );
public void ExitWriteLock(  );</pre>
        <pre>
          <strong>
            <font size="2">Timer</font>
          </strong>
        </pre>
        <p>
          <a name="of these">
          </a>The .NET Framework provides four timers. Two of these are general-purpose
multithreaded timers: 
</p>
        <ul>
          <li>
            <p>
              <tt>System.Threading.Timer</tt>
            </p>
          </li>
          <li>
            <p>
              <tt>System.Timers.Timer</tt>
            </p>
          </li>
        </ul>
        <p>
The other two are special-purpose single-threaded timers: 
</p>
        <ul>
          <li>
            <p>
              <tt>System.Windows.Forms.Timer</tt> (Windows Forms timer)
</p>
          </li>
          <li>
            <p>
              <tt>System.Windows.Threading.DispatcherTimer</tt> (WPF timer)
</p>
          </li>
        </ul>
        <p>
          <a name="like">
          </a>Both are like <tt>System.Timers.Timer</tt><a name="in the"></a> in
the members that they expose (<tt>Interval</tt>, <tt>Tick</tt>, <tt>Start</tt>, and <tt>Stop</tt><a name="used in"></a>)
and are used in a similar manner. However, <font color="#0080ff">they differ in how
they work internally. Instead of using the thread pool to generate timer events, the
Windows Forms and WPF timers rely on the message pumping mechanism of their underlying
user interface model.</font> This means that the <tt>Tick</tt><a name="always fires"></a> event
always fires on the same thread that originally created the timer—which, in a normal
application, is the same thread used to manage all user interface elements and controls.
This has a number of benefits: 
</p>
        <ul>
          <li>
            <p>
You can forget about thread safety.
</p>
          </li>
          <li>
            <p>
A fresh <tt>Tick</tt> will never fire until the previous <tt>Tick</tt> has finished
processing.
</p>
          </li>
          <li>
            <p>
              <a name="from">
              </a>You can update user interface elements and controls directly from <tt>Tick</tt> event
handling code, without calling <tt>Control.Invoke</tt> or <tt>Dispatcher.Invoke</tt>.
</p>
          </li>
        </ul>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=8e0b9d0d-915f-491d-9781-f4af3cf88ffb" />
      </body>
      <title>C# Threading</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,8e0b9d0d-915f-491d-9781-f4af3cf88ffb.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,8e0b9d0d-915f-491d-9781-f4af3cf88ffb.aspx</link>
      <pubDate>Sun, 11 Apr 2010 21:35:30 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://www.albahari.com/threading/part2.aspx" href="http://www.albahari.com/threading/part2.aspx"&gt;http://www.albahari.com/threading/part2.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/CThreading_EDFE/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/CThreading_EDFE/image_thumb.png" width="956" height="710"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Passing Data to a Thread&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;
&lt;br&gt;
&lt;/strong&gt;
&lt;br&gt;
The easiest way to pass arguments to a thread’s target method is to execute a lambda&lt;br&gt;
expression that calls the method with the desired arguments:&lt;br&gt;
&lt;br&gt;
static void Main()&lt;br&gt;
{&lt;br&gt;
Thread t = new Thread ( () =&amp;gt; Print ("Hello from t!") );&lt;br&gt;
t.Start();&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
static void Print (string message) { Console.WriteLine (message); }&lt;br&gt;
&lt;br&gt;
With this approach, you can pass in any number of arguments to the method. You&lt;br&gt;
can even wrap the entire implementation in a multistatement lambda:&lt;br&gt;
&lt;br&gt;
new Thread (() =&amp;gt;&lt;br&gt;
{&lt;br&gt;
Console.WriteLine ("I'm running on another thread!");&lt;br&gt;
Console.WriteLine ("This is so easy!");&lt;br&gt;
}).Start();&lt;br&gt;
&lt;br&gt;
You can do the same thing almost as easily in C# 2.0 with anonymous methods:&lt;br&gt;
&lt;br&gt;
new Thread (delegate()&lt;br&gt;
{&lt;br&gt;
...&lt;br&gt;
}).Start();&lt;br&gt;
&lt;br&gt;
Another technique is to pass an argument into Thread’s Start method: 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
static void Main()&lt;br&gt;
{&lt;br&gt;
Thread t = new Thread (Print);&lt;br&gt;
t.Start ("Hello from t!");&lt;br&gt;
}&lt;br&gt;
static void Print (object messageObj)&lt;br&gt;
{&lt;br&gt;
string message = (string) messageObj; // We need to cast here&lt;br&gt;
Console.WriteLine (message);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
This works because Thread’s constructor is overloaded to accept either of two&lt;br&gt;
delegates:&lt;br&gt;
&lt;br&gt;
public delegate void ThreadStart();&lt;br&gt;
public delegate void ParameterizedThreadStart (object obj);&lt;br&gt;
&lt;br&gt;
The limitation of ParameterizedThreadStart is that it accepts &lt;strong&gt;only one argument&lt;/strong&gt;.&lt;br&gt;
And because it’s of type object, it usually needs to be cast. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Foreground and Background Threads&lt;/strong&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
When a process terminates in this manner, any finally blocks in the execution stack&lt;br&gt;
of background threads are circumvented. This is a problem if your program employs&lt;br&gt;
finally (or using) blocks to perform cleanup work such as releasing resources or&lt;br&gt;
deleting temporary files. To avoid this, you can explicitly wait out such background&lt;br&gt;
threads upon exiting an application. There are two ways to accomplish this:&lt;br&gt;
&lt;br&gt;
• If you’ve created the thread yourself, call Join on the thread.&lt;br&gt;
• If you’re on a pooled thread (see “Thread Pooling” on page 800) use an event&lt;br&gt;
wait handle (see “Signaling with Event Wait Handles” on page 832). 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Thread Pooling&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp; 
&lt;p&gt;
There are a number of ways to enter the thread pool:&lt;br&gt;
• Via the Task Parallel Library or PLINQ (from Framework 4.0)&lt;br&gt;
• By calling ThreadPool.QueueUserWorkItem&lt;br&gt;
• Via asynchronous delegates&lt;br&gt;
• Via BackgroundWorker 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Here’s how you start a worker task via an asynchronous delegate:&lt;br&gt;
1. Instantiate a delegate targeting the method you want to run in parallel (typically&lt;br&gt;
one of the predefined Func delegates).&lt;br&gt;
2. Call BeginInvoke on the delegate, saving its IAsyncResult return value.&lt;br&gt;
BeginInvoke returns immediately to the caller. You can then perform other activities&lt;br&gt;
while the pooled thread is working.&lt;br&gt;
3. When you need the results, call EndInvoke on the delegate, passing in the saved&lt;br&gt;
IAsyncResult object. 
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp; 
&lt;p&gt;
Don’t confuse asynchronous delegates with asynchronous&lt;br&gt;
methods (methods starting with Begin or End, such as&lt;br&gt;
File.BeginRead/File.EndRead). Asynchronous methods follow&lt;br&gt;
a similar protocol outwardly, but they exist to solve a much&lt;br&gt;
more difficult problem, which we describe in Chapter 23. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;Synchronization&lt;/font&gt;&lt;/strong&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Nonblocking Synchronization&lt;/strong&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The following implicitly generate full fences:&lt;br&gt;
• C#’s lock statement (Monitor.Enter/Monitor.Exit)&lt;br&gt;
• All methods on the Interlocked class (we’ll cover these soon)&lt;br&gt;
• Asynchronous callbacks that use the thread pool—these include asynchronous delegates,
APM callbacks (Chapter 23), and Task continuations (Chapter 22)&lt;br&gt;
• Setting and waiting on a signaling construct&lt;br&gt;
• Anything that relies on signaling, such as starting or waiting on a Task 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Memory barriers and locking&lt;br&gt;
&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
C#'s &lt;tt&gt;lock&lt;/tt&gt;&lt;a name="call to"&gt;&lt;/a&gt; statement is in fact a syntactic shortcut
for a call to the methods &lt;tt&gt;Monitor.Enter&lt;/tt&gt; and &lt;tt&gt;Monitor.Exit&lt;/tt&gt;, with a &lt;tt&gt;try&lt;/tt&gt;-&lt;tt&gt;finally&lt;/tt&gt; block.
Here's what's actually happening within the &lt;tt&gt;Go&lt;/tt&gt; method of the preceding example:&lt;pre&gt;Monitor.Enter (locker);
try
{
  if (val2 != 0) Console.WriteLine (val1 / val2);
  val2 = 0;
}
finally { Monitor.Exit (locker); &lt;/pre&gt;
&lt;p&gt;
As we said earlier, Monitor.Enter and Monitor.Exit both generate full fences. So if&lt;br&gt;
we ignore a lock’s mutual exclusion guarantee, we could say that this:&lt;br&gt;
&lt;br&gt;
lock (someField) { ... }&lt;br&gt;
&lt;br&gt;
is equivalent to this:&lt;br&gt;
&lt;br&gt;
Thread.MemoryBarrier(); { ... } Thread.MemoryBarrier();
&lt;/p&gt;
&lt;p&gt;
A &lt;tt&gt;&lt;strong&gt;&lt;font size="2"&gt;Mutex&lt;/font&gt;&lt;/strong&gt;&lt;/tt&gt; is like a C# &lt;tt&gt;lock&lt;/tt&gt;&lt;a name="multiple processes"&gt;&lt;/a&gt;,
but it can work across multiple processes. In other words, &lt;tt&gt;Mutex&lt;/tt&gt; can be computer-wide
as well as application-wide.&lt;br&gt;
&lt;p&gt;
With a &lt;tt&gt;Mutex&lt;/tt&gt; class, you call the &lt;tt&gt;WaitOne&lt;/tt&gt; method to lock and &lt;tt&gt;ReleaseMutex&lt;/tt&gt; to
unlock. Just as with the &lt;tt&gt;lock&lt;/tt&gt; statement, a &lt;tt&gt;Mutex&lt;/tt&gt;&lt;a name="obtained it"&gt;&lt;/a&gt; can
be released only from the same thread that obtained it.&lt;br&gt;
A common use for a cross-process &lt;tt&gt;Mutex&lt;/tt&gt;&lt;a name="of a"&gt;&lt;/a&gt; is to ensure that
only one instance of a program can run at a time. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
A &lt;tt&gt;&lt;font size="2"&gt;&lt;strong&gt;Semaphore&lt;/strong&gt;&lt;/font&gt;&lt;/tt&gt;&lt;a name="Once it"&gt;&lt;/a&gt; is
like a nightclub: it has a certain capacity, enforced by a bouncer. Once it's full,
no more people can enter and a queue builds up outside. Then, for each person that
leaves, one person enters from the head of the queue. The constructor requires a minimum
of two arguments: the number of places currently available in the nightclub and the
club's total capacity.&lt;br&gt;
&lt;a name="IDX-CHP-19-3537"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;br&gt;
A &lt;tt&gt;Semaphore&lt;/tt&gt;&lt;a name="of one"&gt;&lt;/a&gt; with a capacity of one is similar to a &lt;tt&gt;Mutex&lt;/tt&gt; or &lt;tt&gt;lock&lt;/tt&gt;&lt;a name="the"&gt;&lt;/a&gt;,
except that the &lt;tt&gt;&lt;strong&gt;Semaphore&lt;/strong&gt;&lt;/tt&gt;&lt;a name="has no"&gt;&lt;/a&gt;&lt;strong&gt; has
no "owner"—it's &lt;i&gt;thread-agnostic&lt;/i&gt;&lt;/strong&gt;&lt;a name="can call"&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt; Any
thread can call &lt;tt&gt;Release&lt;/tt&gt;&lt;a name="a"&gt;&lt;/a&gt; on a &lt;tt&gt;Semaphore&lt;/tt&gt;, whereas
with &lt;tt&gt;Mutex&lt;/tt&gt; and &lt;tt&gt;lock&lt;/tt&gt;, only the thread that obtained the lock can
release it. 
&lt;p&gt;
&lt;a name="from executing"&gt;&lt;/a&gt;
&lt;br&gt;
Semaphores can be useful in &lt;strong&gt;limiting concurrency&lt;/strong&gt;—preventing too many
threads from executing a particular piece of code at once. In the following example,
five threads try to enter a nightclub that allows only three threads in at once: 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Interlocked&lt;br&gt;
&lt;/strong&gt; 
&lt;p&gt;
Interlocked.Increment (ref _sum); 
&lt;br&gt;
Interlocked.Decrement (ref _sum); 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Interlocked’s mathematical operations are restricted to Increment, Decrement, and
Add. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Signaling with Event Wait Handles&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp; &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; BasicWaitHandle
{ &lt;span class="kwrd"&gt;static&lt;/span&gt; EventWaitHandle wh = &lt;span class="kwrd"&gt;new&lt;/span&gt; AutoResetEvent
(&lt;span class="kwrd"&gt;false&lt;/span&gt;); &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(
) { &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread (Waiter).Start( ); Thread.Sleep (1000); &lt;span class="rem"&gt;//
Pause for a second...&lt;/span&gt; wh.Set( ); &lt;span class="rem"&gt;// Wake up the Waiter.&lt;/span&gt; } &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Waiter(
) { Console.WriteLine (&lt;span class="str"&gt;"Waiting..."&lt;/span&gt;); wh.WaitOne( ); &lt;span class="rem"&gt;//
Wait for notification&lt;/span&gt; Console.WriteLine (&lt;span class="str"&gt;"Notified"&lt;/span&gt;);
} } &lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Thread.Interrupt and Abort&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Calling &lt;tt&gt;Interrupt&lt;/tt&gt; on a blocked thread forcibly releases it, throwing a &lt;tt&gt;ThreadInterruptedException&lt;br&gt;
&lt;/tt&gt;Interrupting a thread does not cause the thread to end, unless the &lt;tt&gt;ThreadInterruptedException&lt;/tt&gt; is
unhandled.
&lt;/p&gt;
&lt;p&gt;
The big difference between &lt;tt&gt;Interrupt&lt;/tt&gt; and &lt;tt&gt;Abort&lt;/tt&gt;&lt;a name="is not"&gt;&lt;/a&gt; is
what happens when it's called on a thread that is not blocked. Whereas &lt;tt&gt;Interrupt&lt;/tt&gt;&lt;a name="doing anything"&gt;&lt;/a&gt; waits
until the thread next blocks before doing anything, &lt;tt&gt;Abort&lt;/tt&gt;&lt;a name="This is"&gt;&lt;/a&gt; throws
an exception on the thread right where it's executing (unmanaged code excepted). This
is a problem because .NET Framework code might be aborted; code that is not abort-safe.
This rules out using &lt;tt&gt;Abort&lt;/tt&gt;&lt;a name="nontrivial context"&gt;&lt;/a&gt; in almost any
nontrivial context. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a name="a pattern"&gt;&lt;/a&gt;An alternative to aborting another thread is to implement
a pattern whereby the worker periodically checks a &lt;tt&gt;cancel&lt;/tt&gt; flag, exiting if
the flag is &lt;tt&gt;true&lt;/tt&gt;&lt;a name="the flag"&gt;&lt;/a&gt;. To abort, the instigator simply
sets the flag, and then waits for the worker to comply. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;BackgroundWorker&lt;br&gt;
&lt;/strong&gt; 
&lt;p&gt;
&lt;tt&gt;BackgroundWorker&lt;/tt&gt;&lt;a name="is a"&gt;&lt;/a&gt; is a helper class in the &lt;tt&gt;System.ComponentModel&lt;/tt&gt;&lt;a name="managing a"&gt;&lt;/a&gt; namespace
for managing a worker thread. It provides the following features:&lt;a name="IDX-CHP-19-3642"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-19-3643"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-19-3644"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-19-3645"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-19-3646"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-19-3647"&gt;&lt;/a&gt; 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
A &lt;tt&gt;cancel&lt;/tt&gt;&lt;a name="for signaling"&gt;&lt;/a&gt; flag for signaling a worker to end without
using &lt;tt&gt;Abort&lt;/tt&gt;
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
A standard protocol for reporting progress, completion, and cancellation
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
An implementation of &lt;tt&gt;IComponent&lt;/tt&gt; allowing it be sited in Visual Studio's designer
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
Exception handling on the worker thread
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="in response"&gt;&lt;/a&gt;The ability to update Windows Forms or WPF controls in response
to worker progress or completion
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="csharpcode"&gt;    bw = &lt;span class="kwrd"&gt;new&lt;/span&gt; BackgroundWorker( );
bw.WorkerReportsProgress = &lt;span class="kwrd"&gt;true&lt;/span&gt;; bw.WorkerSupportsCancellation
= &lt;span class="kwrd"&gt;true&lt;/span&gt;; bw.DoWork += bw_DoWork; bw.ProgressChanged += bw_ProgressChanged;
bw.RunWorkerCompleted += bw_RunWorkerCompleted; bw.&lt;font color="#ff0000"&gt;RunWorkerAsync &lt;/font&gt;(&lt;span class="str"&gt;"Hello
to worker"&lt;/span&gt;); &lt;strong&gt;ReadWRiterLockSlim&lt;/strong&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a name="basic kinds"&gt;&lt;/a&gt;With both classes, there are two basic kinds of lock—a read
lock and a write lock: 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
A write lock is universally exclusive.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
A read lock is compatible with other read locks.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a name="threads trying"&gt;&lt;/a&gt;&lt;font color="#0080ff"&gt;So, a thread holding a write lock
blocks all other threads trying to obtain a read or&lt;/font&gt;&lt;a name="holds a"&gt;&lt;/a&gt;&lt;font color="#0080ff"&gt; write
lock (and vice versa). But if no thread holds a write lock, any number of threads
may concurrently obtain a read lock.&lt;/font&gt; 
&lt;p&gt;
&lt;tt&gt;ReaderWriterLockSlim&lt;/tt&gt; defines the following methods for obtaining and releasing
read/write locks:&lt;pre&gt;public void EnterReadLock(  );
public void ExitReadLock(  );
public void EnterWriteLock(  );
public void ExitWriteLock(  );&lt;/pre&gt;
&lt;pre&gt;&lt;strong&gt;&lt;font size="2"&gt;Timer&lt;/font&gt;&lt;/strong&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a name="of these"&gt;&lt;/a&gt;The .NET Framework provides four timers. Two of these are general-purpose
multithreaded timers: 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
&lt;tt&gt;System.Threading.Timer&lt;/tt&gt;
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;tt&gt;System.Timers.Timer&lt;/tt&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The other two are special-purpose single-threaded timers: 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
&lt;tt&gt;System.Windows.Forms.Timer&lt;/tt&gt; (Windows Forms timer)
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;tt&gt;System.Windows.Threading.DispatcherTimer&lt;/tt&gt; (WPF timer)
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a name="like"&gt;&lt;/a&gt;Both are like &lt;tt&gt;System.Timers.Timer&lt;/tt&gt;&lt;a name="in the"&gt;&lt;/a&gt; in
the members that they expose (&lt;tt&gt;Interval&lt;/tt&gt;, &lt;tt&gt;Tick&lt;/tt&gt;, &lt;tt&gt;Start&lt;/tt&gt;, and &lt;tt&gt;Stop&lt;/tt&gt;&lt;a name="used in"&gt;&lt;/a&gt;)
and are used in a similar manner. However, &lt;font color="#0080ff"&gt;they differ in how
they work internally. Instead of using the thread pool to generate timer events, the
Windows Forms and WPF timers rely on the message pumping mechanism of their underlying
user interface model.&lt;/font&gt; This means that the &lt;tt&gt;Tick&lt;/tt&gt;&lt;a name="always fires"&gt;&lt;/a&gt; event
always fires on the same thread that originally created the timer—which, in a normal
application, is the same thread used to manage all user interface elements and controls.
This has a number of benefits: 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
You can forget about thread safety.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
A fresh &lt;tt&gt;Tick&lt;/tt&gt; will never fire until the previous &lt;tt&gt;Tick&lt;/tt&gt; has finished
processing.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="from"&gt;&lt;/a&gt;You can update user interface elements and controls directly from &lt;tt&gt;Tick&lt;/tt&gt; event
handling code, without calling &lt;tt&gt;Control.Invoke&lt;/tt&gt; or &lt;tt&gt;Dispatcher.Invoke&lt;/tt&gt;.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=8e0b9d0d-915f-491d-9781-f4af3cf88ffb" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,8e0b9d0d-915f-491d-9781-f4af3cf88ffb.aspx</comments>
      <category>DotNet;DotNet / CSharp</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=85d15777-d160-4234-944c-afd12e7236bc</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,85d15777-d160-4234-944c-afd12e7236bc.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,85d15777-d160-4234-944c-afd12e7236bc.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=85d15777-d160-4234-944c-afd12e7236bc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Anonymous Methods<br /><br />
Anonymous methods are a C# 2.0 feature that has been subsumed largely by<br />
C# 3.0 lambda expressions. An anonymous method is like a lambda expression, but<br />
it lacks the following features:<br />
• Implicitly typed parameters<br />
• Expression syntax (an anonymous method must always be a statement block)<br />
• The ability to compile to an expression tree, by assigning to Expression&lt;T&gt;<br /><br />
To write an anonymous method, you include the delegate keyword followed (optionally)<br />
by a parameter declaration and then a method body. For example, given<br />
this delegate:<br /><br />
delegate int Transformer (int i);<br /><br />
we could write and call an anonymous method as follows:<br /><br />
Transformer sqr = delegate (int x) {return x * x;};<br />
Console.WriteLine (sqr(3)); // 9<br /><br />
The first line is semantically equivalent to the following lambda expression:<br /><br />
Transformer sqr = (int x) =&gt; {return x * x;};<br /><br />
Or simply:<br /><br />
Transformer sqr = x =&gt; x * x;<br /><br />
A unique feature of anonymous methods is that you can omit the parameter declaration<br />
entirely—even if the delegate expects them. This can be useful in declaring<br />
events with a default empty handler:<br /><br />
public event EventHandler Clicked = delegate { };<br /><br />
This avoids the need for a null check before firing the event. The following is also<br />
legal:<br /><br />
Clicked += delegate { Console.WriteLine ("clicked"); }; // No parameters<br /><br />
Anonymous methods capture outer variables in the same way lambda expressions<br />
do.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=85d15777-d160-4234-944c-afd12e7236bc" />
      </body>
      <title>Anonymous Methods</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,85d15777-d160-4234-944c-afd12e7236bc.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,85d15777-d160-4234-944c-afd12e7236bc.aspx</link>
      <pubDate>Sun, 11 Apr 2010 18:58:40 GMT</pubDate>
      <description>&lt;p&gt;
Anonymous Methods&lt;br&gt;
&lt;br&gt;
Anonymous methods are a C# 2.0 feature that has been subsumed largely by&lt;br&gt;
C# 3.0 lambda expressions. An anonymous method is like a lambda expression, but&lt;br&gt;
it lacks the following features:&lt;br&gt;
• Implicitly typed parameters&lt;br&gt;
• Expression syntax (an anonymous method must always be a statement block)&lt;br&gt;
• The ability to compile to an expression tree, by assigning to Expression&amp;lt;T&amp;gt;&lt;br&gt;
&lt;br&gt;
To write an anonymous method, you include the delegate keyword followed (optionally)&lt;br&gt;
by a parameter declaration and then a method body. For example, given&lt;br&gt;
this delegate:&lt;br&gt;
&lt;br&gt;
delegate int Transformer (int i);&lt;br&gt;
&lt;br&gt;
we could write and call an anonymous method as follows:&lt;br&gt;
&lt;br&gt;
Transformer sqr = delegate (int x) {return x * x;};&lt;br&gt;
Console.WriteLine (sqr(3)); // 9&lt;br&gt;
&lt;br&gt;
The first line is semantically equivalent to the following lambda expression:&lt;br&gt;
&lt;br&gt;
Transformer sqr = (int x) =&amp;gt; {return x * x;};&lt;br&gt;
&lt;br&gt;
Or simply:&lt;br&gt;
&lt;br&gt;
Transformer sqr = x =&amp;gt; x * x;&lt;br&gt;
&lt;br&gt;
A unique feature of anonymous methods is that you can omit the parameter declaration&lt;br&gt;
entirely—even if the delegate expects them. This can be useful in declaring&lt;br&gt;
events with a default empty handler:&lt;br&gt;
&lt;br&gt;
public event EventHandler Clicked = delegate { };&lt;br&gt;
&lt;br&gt;
This avoids the need for a null check before firing the event. The following is also&lt;br&gt;
legal:&lt;br&gt;
&lt;br&gt;
Clicked += delegate { Console.WriteLine ("clicked"); }; // No parameters&lt;br&gt;
&lt;br&gt;
Anonymous methods capture outer variables in the same way lambda expressions&lt;br&gt;
do.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=85d15777-d160-4234-944c-afd12e7236bc" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,85d15777-d160-4234-944c-afd12e7236bc.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=b4f290a6-2d12-4e65-811b-19865237da5a</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,b4f290a6-2d12-4e65-811b-19865237da5a.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,b4f290a6-2d12-4e65-811b-19865237da5a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b4f290a6-2d12-4e65-811b-19865237da5a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx" href="http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx">http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx</a>
          <br />
        </p>
        <p>
          <strong>Add Web Reference </strong>is a wrapper over <a href="http://msdn.microsoft.com/en-us/library/7h3ystb6%28VS.80%29.aspx">wsdl.exe</a> and
can be used to create proxies for .NET 1.1 or 2.0 clients. Of course this means when
you are pointing to a WCF service you have to be pointing to an endpoint that uses
basicHttpBinding (as I was). 
</p>
        <p>
          <strong>Add Service Reference </strong>is a wrapper over <a href="http://msdn.microsoft.com/en-us/library/aa347733.aspx">svcutil.exe</a> and
also creates clients proxies (and additionally web.config entries). These proxies,
however, can only be consumed by .NET 3.0+ clients. 
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=b4f290a6-2d12-4e65-811b-19865237da5a" />
      </body>
      <title>The Difference Between &amp;ldquo;Add Web Reference&amp;rdquo; and &amp;ldquo;Add Service Reference&amp;rdquo;</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,b4f290a6-2d12-4e65-811b-19865237da5a.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,b4f290a6-2d12-4e65-811b-19865237da5a.aspx</link>
      <pubDate>Sun, 11 Apr 2010 05:29:03 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx" href="http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx"&gt;http://andrewtokeley.net/archive/2008/07/10/the-difference-between-ldquoadd-web-referencerdquo-and-ldquoadd-service-referencerdquo.aspx&lt;/a&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Add Web Reference &lt;/strong&gt;is a wrapper over &lt;a href="http://msdn.microsoft.com/en-us/library/7h3ystb6%28VS.80%29.aspx"&gt;wsdl.exe&lt;/a&gt; and
can be used to create proxies for .NET 1.1 or 2.0 clients. Of course this means when
you are pointing to a WCF service you have to be pointing to an endpoint that uses
basicHttpBinding (as I was). 
&lt;p&gt;
&lt;strong&gt;Add Service Reference &lt;/strong&gt;is a wrapper over &lt;a href="http://msdn.microsoft.com/en-us/library/aa347733.aspx"&gt;svcutil.exe&lt;/a&gt; and
also creates clients proxies (and additionally web.config entries). These proxies,
however, can only be consumed by .NET 3.0+ clients. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=b4f290a6-2d12-4e65-811b-19865237da5a" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,b4f290a6-2d12-4e65-811b-19865237da5a.aspx</comments>
      <category>DotNet;DotNet / WCF</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=0a2dc92d-99da-4699-9c88-65595f5fe355</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,0a2dc92d-99da-4699-9c88-65595f5fe355.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,0a2dc92d-99da-4699-9c88-65595f5fe355.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0a2dc92d-99da-4699-9c88-65595f5fe355</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="2">Below is a picture of the HTTP Request Pipeline and its three replaceable
component types: <strong>HttpHandler, HttpApplication, and HttpModule.</strong> As
requests come in, they are queued up and assigned to a worker thread that then processes
the request by interacting with each of these component types. </font>
        </p>
        <p>
          <a name="115">
            <font size="2">
            </font>
          </a>
          <a name="ch0">
          </a> 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/HTTPRequestPipeline_8F9A/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/HTTPRequestPipeline_8F9A/image_thumb.png" width="397" height="195" />
          </a>
        </p>
        <p>
          <br />
          <font size="2">Figure 2-4: The HTTP Request Pipeline allows developers to replace
components such as HttpHandler, HttpApplication, and HttpModule.</font>
        </p>
        <p>
          <font size="2">The ultimate destination of any request is the endpoint, which is modeled
in the HTTP Request Pipeline by using an HttpHandler class, which implements the IHttpHandler
interface. As a developer, you can create a custom HttpHandler component and plug
it into the HTTP Request Pipeline by adding configuration elements to the web.config
file.<br /></font>
        </p>
        <p>
          <font size="2">The HTTP Request Pipeline places an HttpApplication component in front
of the HttpHandler. On an application-wide basis, incoming requests are always routed
through the HttpApplication before they reach the target HttpHandler, thus giving
the HttpApplication the ability to pre-process any request no matter which HttpHandler
it is being routed to. This preprocessing stage is handled through a series of events
that are defined inside the HttpApplication class such as BeginRequest, AuthenticateRequest,
and AuthorizeRequest.<br /></font>
        </p>
        <p>
          <font size="2">In situations when you don’t want to use a custom HttpApplication component,
the ASP.NET Framework initializes the HTTP Request Pipeline with a standard HttpApplication
object that provides default behavior. However, you can replace this standard component
by creating a </font>
          <a name="116">
          </a>
          <a name="IDX-">
          </a>
          <font size="2">file named
global.asax and placing it in the root directory of the hosting ASP.NET application.
For example, you can create a global.asax that looks like the following: </font>
        </p>
        <pre>
          <font size="2">&lt;%@ Application Language="C#" %&gt; &lt;script runat="server"&gt;
protected void Application_AuthenticateRequest(object sender, EventArgs e) { // your
code goes here for request authentication } protected void Application_AuthorizeRequest(object
sender, EventArgs e) { // your code goes here for request authorization } &lt;/script&gt;</font>
        </pre>
        <p>
          <font size="2">The third replaceable component type in the HTTP Request Pipeline is
the HttpModule. The HttpModule is similar to the HttpApplication component in that
it is designed to handle events defined by the HttpApplication class and is processed
before control is passed to any HttpHandler classes. For example, you can create a
custom HttpModule component to handle request-level events such as BeginRequest, AuthenticateRequest,
and AuthorizeRequest. As with the HttpHandler, an HttpModule class is defined with
an interface. You can create a class that implements the IHttpModule interface and
plug it into the HTTP Request Pipeline by adding configuration elements to the web.config
file.<br /></font>
        </p>
        <p>
          <font size="2">Whereas custom HttpApplication components can be defined as simple
text files with an .asax extension, custom HttpModule components are always compiled
as classes within assembly DLLs. To add a custom HttpModule component into the HTTP
Request Pipeline, you then add entries into a web.config file.<br /></font>
        </p>
        <p>
          <font size="2">While an HttpApplication component and an HttpModule component are
similar in what they do, the HttpModule contains a few noteworthy differences. First,
you are not limited to one HttpModule per application as you are with the HttpApplication
components. The web.config file for an ASP.NET application can add in several different
HttpModule components. Second, HttpModule components can be configured at the machine
level. In fact, the ASP.NET Framework ships with several different HttpModule components
that are automatically configured at the machine level to provide ASP.NET functionality
for things such as Windows authentication, Forms authentication, and output caching.<br /></font>
        </p>
        <p>
          <font size="2">The final component that we want to discuss with respect to the HTTP
Request Pipeline is HttpContext. As ASP.NET initializes a request to send to the HTTP
Request Pipeline, it creates an object from the HttpContext class and initializes
it with important contextual information.</font>
        </p>
        <p>
          <font size="2">From a timing perspective, it’s important to see that ASP.NET creates
this object before any custom code inside the HTTP Request Pipeline has a chance to
begin execution. This means that you can always program against the HttpContext object
and the child objects that it </font>
          <a name="117">
          </a>
          <a name="IDX-">
          </a>
          <font size="2">contains,
such as Request, User, and Response. Whenever you are authoring a component that is
to execute within the HTTP Request Pipeline, you can write code that looks like the
following: </font>
        </p>
        <pre>
          <font size="2">HttpContext currentContext = HttpContext.Current; string incomingUrl
= currentContext.Request.Url; string currentUser = currentContext.User.Identity.Name;
currentContext.Response.Write("Hello world");</font>
        </pre>
        <p>
          <font size="2">
          </font>
        </p>
        <p>
          <font size="2">
          </font>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=0a2dc92d-99da-4699-9c88-65595f5fe355" />
      </body>
      <title>HTTP Request Pipeline</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,0a2dc92d-99da-4699-9c88-65595f5fe355.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,0a2dc92d-99da-4699-9c88-65595f5fe355.aspx</link>
      <pubDate>Fri, 09 Apr 2010 14:12:43 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="2"&gt;Below is a picture of the HTTP Request Pipeline and its three replaceable
component types: &lt;strong&gt;HttpHandler, HttpApplication, and HttpModule.&lt;/strong&gt; As
requests come in, they are queued up and assigned to a worker thread that then processes
the request by interacting with each of these component types. &lt;/font&gt; 
&lt;p&gt;
&lt;a name="115"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/a&gt;&lt;a name="ch0"&gt;&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/HTTPRequestPipeline_8F9A/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/HTTPRequestPipeline_8F9A/image_thumb.png" width="397" height="195"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;font size="2"&gt;Figure 2-4: The HTTP Request Pipeline allows developers to replace
components such as HttpHandler, HttpApplication, and HttpModule.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;The ultimate destination of any request is the endpoint, which is modeled
in the HTTP Request Pipeline by using an HttpHandler class, which implements the IHttpHandler
interface. As a developer, you can create a custom HttpHandler component and plug
it into the HTTP Request Pipeline by adding configuration elements to the web.config
file.&lt;br&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;The HTTP Request Pipeline places an HttpApplication component in front
of the HttpHandler. On an application-wide basis, incoming requests are always routed
through the HttpApplication before they reach the target HttpHandler, thus giving
the HttpApplication the ability to pre-process any request no matter which HttpHandler
it is being routed to. This preprocessing stage is handled through a series of events
that are defined inside the HttpApplication class such as BeginRequest, AuthenticateRequest,
and AuthorizeRequest.&lt;br&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;In situations when you don’t want to use a custom HttpApplication component,
the ASP.NET Framework initializes the HTTP Request Pipeline with a standard HttpApplication
object that provides default behavior. However, you can replace this standard component
by creating a &lt;/font&gt;&lt;a name="116"&gt;&lt;/a&gt;&lt;a name="IDX-"&gt;&lt;/a&gt;&lt;font size="2"&gt;file named
global.asax and placing it in the root directory of the hosting ASP.NET application.
For example, you can create a global.asax that looks like the following: &lt;/font&gt;&lt;pre&gt;&lt;font size="2"&gt;&amp;lt;%@
Application Language="C#" %&amp;gt; &amp;lt;script runat="server"&amp;gt; protected void Application_AuthenticateRequest(object
sender, EventArgs e) { // your code goes here for request authentication } protected
void Application_AuthorizeRequest(object sender, EventArgs e) { // your code goes
here for request authorization } &amp;lt;/script&amp;gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;font size="2"&gt;The third replaceable component type in the HTTP Request Pipeline is
the HttpModule. The HttpModule is similar to the HttpApplication component in that
it is designed to handle events defined by the HttpApplication class and is processed
before control is passed to any HttpHandler classes. For example, you can create a
custom HttpModule component to handle request-level events such as BeginRequest, AuthenticateRequest,
and AuthorizeRequest. As with the HttpHandler, an HttpModule class is defined with
an interface. You can create a class that implements the IHttpModule interface and
plug it into the HTTP Request Pipeline by adding configuration elements to the web.config
file.&lt;br&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;Whereas custom HttpApplication components can be defined as simple
text files with an .asax extension, custom HttpModule components are always compiled
as classes within assembly DLLs. To add a custom HttpModule component into the HTTP
Request Pipeline, you then add entries into a web.config file.&lt;br&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;While an HttpApplication component and an HttpModule component are
similar in what they do, the HttpModule contains a few noteworthy differences. First,
you are not limited to one HttpModule per application as you are with the HttpApplication
components. The web.config file for an ASP.NET application can add in several different
HttpModule components. Second, HttpModule components can be configured at the machine
level. In fact, the ASP.NET Framework ships with several different HttpModule components
that are automatically configured at the machine level to provide ASP.NET functionality
for things such as Windows authentication, Forms authentication, and output caching.&lt;br&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;The final component that we want to discuss with respect to the HTTP
Request Pipeline is HttpContext. As ASP.NET initializes a request to send to the HTTP
Request Pipeline, it creates an object from the HttpContext class and initializes
it with important contextual information.&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;From a timing perspective, it’s important to see that ASP.NET creates
this object before any custom code inside the HTTP Request Pipeline has a chance to
begin execution. This means that you can always program against the HttpContext object
and the child objects that it &lt;/font&gt;&lt;a name="117"&gt;&lt;/a&gt;&lt;a name="IDX-"&gt;&lt;/a&gt;&lt;font size="2"&gt;contains,
such as Request, User, and Response. Whenever you are authoring a component that is
to execute within the HTTP Request Pipeline, you can write code that looks like the
following: &lt;/font&gt;&lt;pre&gt;&lt;font size="2"&gt;HttpContext currentContext = HttpContext.Current;
string incomingUrl = currentContext.Request.Url; string currentUser = currentContext.User.Identity.Name;
currentContext.Response.Write("Hello world");&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=0a2dc92d-99da-4699-9c88-65595f5fe355" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,0a2dc92d-99da-4699-9c88-65595f5fe355.aspx</comments>
      <category>DotNet;DotNet / ASP</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=b291da7b-adcc-4ed4-9525-208ac19ad6b0</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,b291da7b-adcc-4ed4-9525-208ac19ad6b0.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,b291da7b-adcc-4ed4-9525-208ac19ad6b0.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b291da7b-adcc-4ed4-9525-208ac19ad6b0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="2">1. Partial class</font>
        </p>
        <p>
          <font size="2">2. Partial method</font>
        </p>
        <p>
          <font size="2">3. Customize event handlers</font>
        </p>
        <p>
          <font size="2">4. Add IDataErrorInfo 
<br /></font>
          <a title="http://www.asp.net/Learn/mvc/tutorial-37-cs.aspx" href="http://www.asp.net/Learn/mvc/tutorial-37-cs.aspx">
            <font size="2">http://www.asp.net/Learn/mvc/tutorial-37-cs.aspx</font>
          </a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=b291da7b-adcc-4ed4-9525-208ac19ad6b0" />
      </body>
      <title>How to extend EDM</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,b291da7b-adcc-4ed4-9525-208ac19ad6b0.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,b291da7b-adcc-4ed4-9525-208ac19ad6b0.aspx</link>
      <pubDate>Thu, 08 Apr 2010 15:55:52 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="2"&gt;1. Partial class&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;2. Partial method&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;3. Customize event handlers&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;4. Add IDataErrorInfo 
&lt;br&gt;
&lt;/font&gt;&lt;a title="http://www.asp.net/Learn/mvc/tutorial-37-cs.aspx" href="http://www.asp.net/Learn/mvc/tutorial-37-cs.aspx"&gt;&lt;font size="2"&gt;http://www.asp.net/Learn/mvc/tutorial-37-cs.aspx&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=b291da7b-adcc-4ed4-9525-208ac19ad6b0" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,b291da7b-adcc-4ed4-9525-208ac19ad6b0.aspx</comments>
      <category>Database;DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=5c64cec1-af6e-4230-8efb-12f334a8ae0e</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,5c64cec1-af6e-4230-8efb-12f334a8ae0e.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,5c64cec1-af6e-4230-8efb-12f334a8ae0e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5c64cec1-af6e-4230-8efb-12f334a8ae0e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="2">From C# 3.0 in Nutshell</font>
        </p>
        <p>
          <a name="An important">
          </a>
          <font size="3">(lulu: Use toArray() to force immediate
execution)</font>
        </p>
        <p>
  
</p>
        <p>
          <font size="2">An important feature of most query operators is that they execute not
when constructed, but when enumerated (in other words, when <tt>MoveNext</tt></font>
          <a name="on its">
          </a>
          <font size="2"> is
called on its enumerator). Consider the following query:</font>
          <a name="IDX-CHP-8-1826">
          </a>
          <a name="IDX-CHP-8-1827">
          </a>
          <a name="IDX-CHP-8-1828">
          </a>
          <a name="IDX-CHP-8-1829">
          </a>
        </p>
        <pre>
          <font size="2">var numbers = new List&lt;int&gt;( ); numbers.Add (1); IEnumerable&lt;int&gt;
query = numbers.Select (n =&gt; n * 10); // Build query numbers.Add (2); // Sneak
in an extra element foreach (int n in query) Console.Write (n + "|"); // 10|20| </font>
        </pre>
        <p>
          <a name="extra number">
          </a>
          <font size="2">The extra number that we sneaked into the
list after</font>
          <a name="until the">
          </a>
          <font size="2"> constructing the query is
included in the result, because it's not <font color="#0080ff">until the <tt>foreach</tt></font></font>
          <a name="or sorting">
          </a>
          <font size="2">
            <font color="#0080ff"> statement
runs </font>that any filtering or sorting takes place. This is called <i>deferred</i> or <i>lazy</i> evaluation.
All standard query operators provide deferred execution, with the following exceptions:</font>
          <a name="IDX-CHP-8-1830">
          </a>
        </p>
        <ul>
          <li>
            <p>
              <a name="as">
              </a>
              <font size="2">Operators that return a single element or scalar value,
such as <tt>First</tt> or <tt>Count</tt></font>
            </p>
          </li>
          <li>
            <p>
              <font size="2">The following <i>conversion operators</i>:</font>
            </p>
            <pre>
              <font size="2">ToArray, ToList, ToDictionary, ToLookup </font>
            </pre>
          </li>
        </ul>
        <p>
          <a name="because their">
          </a>
          <font size="2">These operators cause immediate query execution
because their result types have no mechanism for providing deferred execution. The <tt>Count</tt></font>
          <a name="following query">
          </a>
          <font size="2"> method,
for instance, returns a simple integer, which doesn't then get enumerated. The following
query is executed immediately:</font>
        </p>
        <pre>
          <font size="2">int matches = numbers.Where (n =&gt; n &lt; 2).Count( ); //
1 </font>
        </pre>
        <p>
          <a name="execution is">
          </a>
          <font size="2">Deferred execution is important because
it decouples query construction from query execution</font>
          <a name="well as">
          </a>
          <font size="2">.
This allows you to construct a query in several steps, as well as making LINQ to SQL
queries possible.</font>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=5c64cec1-af6e-4230-8efb-12f334a8ae0e" />
      </body>
      <title>Linq Defered Execution</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,5c64cec1-af6e-4230-8efb-12f334a8ae0e.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,5c64cec1-af6e-4230-8efb-12f334a8ae0e.aspx</link>
      <pubDate>Thu, 08 Apr 2010 14:28:06 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="2"&gt;From C# 3.0 in Nutshell&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a name="An important"&gt;&lt;/a&gt;&lt;font size="3"&gt;(lulu: Use toArray() to force immediate
execution)&lt;/font&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;font size="2"&gt;An important feature of most query operators is that they execute not
when constructed, but when enumerated (in other words, when &lt;tt&gt;MoveNext&lt;/tt&gt;&lt;/font&gt;&lt;a name="on its"&gt;&lt;/a&gt;&lt;font size="2"&gt; is
called on its enumerator). Consider the following query:&lt;/font&gt;&lt;a name="IDX-CHP-8-1826"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-8-1827"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-8-1828"&gt;&lt;/a&gt;&lt;a name="IDX-CHP-8-1829"&gt;&lt;/a&gt;&lt;pre&gt;&lt;font size="2"&gt;var
numbers = new List&amp;lt;int&amp;gt;( ); numbers.Add (1); IEnumerable&amp;lt;int&amp;gt; query =
numbers.Select (n =&amp;gt; n * 10); // Build query numbers.Add (2); // Sneak in an extra
element foreach (int n in query) Console.Write (n + "|"); // 10|20| &lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a name="extra number"&gt;&lt;/a&gt;&lt;font size="2"&gt;The extra number that we sneaked into the
list after&lt;/font&gt;&lt;a name="until the"&gt;&lt;/a&gt;&lt;font size="2"&gt; constructing the query is
included in the result, because it's not &lt;font color="#0080ff"&gt;until the &lt;tt&gt;foreach&lt;/tt&gt;&lt;/font&gt;&lt;/font&gt;&lt;a name="or sorting"&gt;&lt;/a&gt;&lt;font size="2"&gt;&lt;font color="#0080ff"&gt; statement
runs &lt;/font&gt;that any filtering or sorting takes place. This is called &lt;i&gt;deferred&lt;/i&gt; or &lt;i&gt;lazy&lt;/i&gt; evaluation.
All standard query operators provide deferred execution, with the following exceptions:&lt;/font&gt;&lt;a name="IDX-CHP-8-1830"&gt;&lt;/a&gt; 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="as"&gt;&lt;/a&gt;&lt;font size="2"&gt;Operators that return a single element or scalar value,
such as &lt;tt&gt;First&lt;/tt&gt; or &lt;tt&gt;Count&lt;/tt&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;font size="2"&gt;The following &lt;i&gt;conversion operators&lt;/i&gt;:&lt;/font&gt;&lt;pre&gt;&lt;font size="2"&gt;ToArray,
ToList, ToDictionary, ToLookup &lt;/font&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a name="because their"&gt;&lt;/a&gt;&lt;font size="2"&gt;These operators cause immediate query execution
because their result types have no mechanism for providing deferred execution. The &lt;tt&gt;Count&lt;/tt&gt;&lt;/font&gt;&lt;a name="following query"&gt;&lt;/a&gt;&lt;font size="2"&gt; method,
for instance, returns a simple integer, which doesn't then get enumerated. The following
query is executed immediately:&lt;/font&gt;&lt;pre&gt;&lt;font size="2"&gt;int matches = numbers.Where
(n =&amp;gt; n &amp;lt; 2).Count( ); // 1 &lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a name="execution is"&gt;&lt;/a&gt;&lt;font size="2"&gt;Deferred execution is important because
it decouples query construction from query execution&lt;/font&gt;&lt;a name="well as"&gt;&lt;/a&gt;&lt;font size="2"&gt;.
This allows you to construct a query in several steps, as well as making LINQ to SQL
queries possible.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=5c64cec1-af6e-4230-8efb-12f334a8ae0e" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,5c64cec1-af6e-4230-8efb-12f334a8ae0e.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=df53fdf5-fa90-4f60-95cb-dee4deddfbd4</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,df53fdf5-fa90-4f60-95cb-dee4deddfbd4.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,df53fdf5-fa90-4f60-95cb-dee4deddfbd4.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=df53fdf5-fa90-4f60-95cb-dee4deddfbd4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://stackoverflow.com/questions/40022/best-way-to-update-linq-to-sql-classes-after-database-schema-change" href="http://stackoverflow.com/questions/40022/best-way-to-update-linq-to-sql-classes-after-database-schema-change">http://stackoverflow.com/questions/40022/best-way-to-update-linq-to-sql-classes-after-database-schema-change</a>
        </p>
        <p>
You can use SQLMetal.exe to generate your dbml and or cs/vb file. Use a pre-build
script to start it and target the directory where your datacontext project belongs. 
</p>
        <pre>
          <code>C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sqlmetal.exe 
<br />
  /server:&lt;SERVER&gt; 
<br />
  /database:&lt;database&gt; 
<br />
  /code:"path\Solution\DataContextProject\dbContext.cs" 
<br />
  /language:csharp 
<br />
  /namespace:&lt;your namespace&gt;<br /></code>
        </pre>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=df53fdf5-fa90-4f60-95cb-dee4deddfbd4" />
      </body>
      <title>Best way to update LINQ to SQL classes after database schema change</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,df53fdf5-fa90-4f60-95cb-dee4deddfbd4.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,df53fdf5-fa90-4f60-95cb-dee4deddfbd4.aspx</link>
      <pubDate>Thu, 08 Apr 2010 14:21:55 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://stackoverflow.com/questions/40022/best-way-to-update-linq-to-sql-classes-after-database-schema-change" href="http://stackoverflow.com/questions/40022/best-way-to-update-linq-to-sql-classes-after-database-schema-change"&gt;http://stackoverflow.com/questions/40022/best-way-to-update-linq-to-sql-classes-after-database-schema-change&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
You can use SQLMetal.exe to generate your dbml and or cs/vb file. Use a pre-build
script to start it and target the directory where your datacontext project belongs. &lt;pre&gt;&lt;code&gt;C:\Program
Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sqlmetal.exe 
&lt;br&gt;
&amp;nbsp; /server:&amp;lt;SERVER&amp;gt; 
&lt;br&gt;
&amp;nbsp; /database:&amp;lt;database&amp;gt; 
&lt;br&gt;
&amp;nbsp; /code:"path\Solution\DataContextProject\dbContext.cs" 
&lt;br&gt;
&amp;nbsp; /language:csharp 
&lt;br&gt;
&amp;nbsp; /namespace:&amp;lt;your namespace&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=df53fdf5-fa90-4f60-95cb-dee4deddfbd4" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,df53fdf5-fa90-4f60-95cb-dee4deddfbd4.aspx</comments>
      <category>Database;DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=c79f9b7e-7634-49d2-a780-9f0c41030066</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,c79f9b7e-7634-49d2-a780-9f0c41030066.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,c79f9b7e-7634-49d2-a780-9f0c41030066.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c79f9b7e-7634-49d2-a780-9f0c41030066</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/e05592358bc8.NetDictionaryComparison_895/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/e05592358bc8.NetDictionaryComparison_895/image_thumb.png" width="502" height="440" />
          </a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=c79f9b7e-7634-49d2-a780-9f0c41030066" />
      </body>
      <title>.Net Dictionary Comparison</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,c79f9b7e-7634-49d2-a780-9f0c41030066.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,c79f9b7e-7634-49d2-a780-9f0c41030066.aspx</link>
      <pubDate>Thu, 08 Apr 2010 04:36:43 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/e05592358bc8.NetDictionaryComparison_895/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/e05592358bc8.NetDictionaryComparison_895/image_thumb.png" width="502" height="440"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=c79f9b7e-7634-49d2-a780-9f0c41030066" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,c79f9b7e-7634-49d2-a780-9f0c41030066.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=f0181029-552c-4299-8553-85251afbbcdd</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,f0181029-552c-4299-8553-85251afbbcdd.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,f0181029-552c-4299-8553-85251afbbcdd.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f0181029-552c-4299-8553-85251afbbcdd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">using</span> System;</pre>
          <pre>
            <span class="lnum"> 2: </span>
            <span class="kwrd">using</span> Kellerman.Business; <span class="rem">//Reference
to class to test</span></pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>
            <span class="kwrd">using</span> NUnit.Framework; <span class="rem">//This
must be included to do the asserts</span></pre>
          <pre>
            <span class="lnum"> 4: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">namespace</span> Kellerman.BusinessTest</pre>
          <pre>
            <span class="lnum"> 6: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>
            <span class="rem">//Tests for the
Invoice Business Object</span>
          </pre>
          <pre>
            <span class="lnum"> 8: </span> [TestFixture]</pre>
          <pre class="alt">
            <span class="lnum"> 9: </span> [Category(<span class="str">"Optional
Category Attribute"</span>), Description(<span class="str">"Optional Description"</span>)]</pre>
          <pre>
            <span class="lnum"> 10: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">class</span> InvoiceTest</pre>
          <pre class="alt">
            <span class="lnum"> 11: </span> {</pre>
          <pre>
            <span class="lnum"> 12: </span>
            <span class="kwrd">private</span> Invoice _invoice
= <span class="kwrd">null</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 13: </span>
            <span class="rem">//Code that is
run before each test</span>
          </pre>
          <pre>
            <span class="lnum"> 14: </span> [SetUp]</pre>
          <pre class="alt">
            <span class="lnum"> 15: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> Initialize()</pre>
          <pre>
            <span class="lnum"> 16: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 17: </span> _invoice = <span class="kwrd">new</span> Invoice();</pre>
          <pre>
            <span class="lnum"> 18: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 19: </span>
            <span class="rem">//Code that is
run after each test</span>
          </pre>
          <pre>
            <span class="lnum"> 20: </span> [TearDown]</pre>
          <pre class="alt">
            <span class="lnum"> 21: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> Cleanup()</pre>
          <pre>
            <span class="lnum"> 22: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 23: </span> }</pre>
          <pre>
            <span class="lnum"> 24: </span>
            <span class="rem">//Example test and asserts</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 25: </span> [Test, Description(<span class="str">"Property
Tests"</span>)]</pre>
          <pre>
            <span class="lnum"> 26: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> InvoiceIdTest()</pre>
          <pre class="alt">
            <span class="lnum"> 27: </span> {</pre>
          <pre>
            <span class="lnum"> 28: </span>
            <span class="kwrd">int</span> expected = 7;</pre>
          <pre class="alt">
            <span class="lnum"> 29: </span> _invoice.InvoiceId = expected;</pre>
          <pre>
            <span class="lnum"> 30: </span> Assert.AreEqual(expected,</pre>
          <pre class="alt">
            <span class="lnum"> 31: </span> _invoice.InvoiceId,</pre>
          <pre>
            <span class="lnum"> 32: </span>
            <span class="str">"Kellerman.Business.Invoice.InvoiceId
not set correctly"</span>);</pre>
          <pre class="alt">
            <span class="lnum"> 33: </span>
            <span class="rem">//Other example
Asserts</span>
          </pre>
          <pre>
            <span class="lnum"> 34: </span> Assert.IsTrue(<span class="kwrd">true</span>);</pre>
          <pre class="alt">
            <span class="lnum"> 35: </span> Assert.IsFalse(<span class="kwrd">false</span>);</pre>
          <pre>
            <span class="lnum"> 36: </span> Assert.IsNull(<span class="kwrd">null</span>);</pre>
          <pre class="alt">
            <span class="lnum"> 37: </span> Assert.IsNotNull(_invoice);</pre>
          <pre>
            <span class="lnum"> 38: </span> Assert.IsEmpty(<span class="kwrd">string</span>.Empty);</pre>
          <pre class="alt">
            <span class="lnum"> 39: </span> Assert.IsNotEmpty(<span class="str">"This
string is not empty"</span>);</pre>
          <pre>
            <span class="lnum"> 40: </span> Assert.Fail(<span class="str">"This is a failure
message"</span>);</pre>
          <pre class="alt">
            <span class="lnum"> 41: </span> }</pre>
          <pre>
            <span class="lnum"> 42: </span>
            <span class="rem">//Expected Exception Test</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 43: </span> [Test]</pre>
          <pre>
            <span class="lnum"> 44: </span> [ExpectedException(<span class="kwrd">typeof</span>(System.Security.SecurityException))]</pre>
          <pre class="alt">
            <span class="lnum"> 45: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> DeleteTestNoRights()</pre>
          <pre>
            <span class="lnum"> 46: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 47: </span> _invoice.Delete();</pre>
          <pre>
            <span class="lnum"> 48: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 49: </span>
            <span class="rem">//Not Implemented
Test</span>
          </pre>
          <pre>
            <span class="lnum"> 50: </span> [Test]</pre>
          <pre class="alt">
            <span class="lnum"> 51: </span> [Ignore(<span class="str">"Please
implement"</span>)]</pre>
          <pre>
            <span class="lnum"> 52: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> UpdateTestNoRights()</pre>
          <pre class="alt">
            <span class="lnum"> 53: </span> {</pre>
          <pre>
            <span class="lnum"> 54: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 55: </span> }</pre>
          <pre>
            <span class="lnum"> 56: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=f0181029-552c-4299-8553-85251afbbcdd" />
      </body>
      <title>NUnit Quick Example</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,f0181029-552c-4299-8553-85251afbbcdd.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,f0181029-552c-4299-8553-85251afbbcdd.aspx</link>
      <pubDate>Wed, 07 Apr 2010 18:27:00 GMT</pubDate>
      <description>&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Kellerman.Business; &lt;span class="rem"&gt;//Reference
to class to test&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; NUnit.Framework; &lt;span class="rem"&gt;//This
must be included to do the asserts&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Kellerman.BusinessTest&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="rem"&gt;//Tests for the
Invoice Business Object&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; [TestFixture]&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; [Category(&lt;span class="str"&gt;"Optional
Category Attribute"&lt;/span&gt;), Description(&lt;span class="str"&gt;"Optional Description"&lt;/span&gt;)]&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; InvoiceTest&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; Invoice _invoice
= &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; &lt;span class="rem"&gt;//Code that is
run before each test&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; [SetUp]&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; _invoice = &lt;span class="kwrd"&gt;new&lt;/span&gt; Invoice();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt; &lt;span class="rem"&gt;//Code that is
run after each test&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt; [TearDown]&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Cleanup()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 22: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 23: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 24: &lt;/span&gt; &lt;span class="rem"&gt;//Example test and asserts&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 25: &lt;/span&gt; [Test, Description(&lt;span class="str"&gt;"Property
Tests"&lt;/span&gt;)]&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 26: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InvoiceIdTest()&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 27: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 28: &lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; expected = 7;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 29: &lt;/span&gt; _invoice.InvoiceId = expected;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 30: &lt;/span&gt; Assert.AreEqual(expected,&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 31: &lt;/span&gt; _invoice.InvoiceId,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 32: &lt;/span&gt; &lt;span class="str"&gt;"Kellerman.Business.Invoice.InvoiceId
not set correctly"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 33: &lt;/span&gt; &lt;span class="rem"&gt;//Other example
Asserts&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 34: &lt;/span&gt; Assert.IsTrue(&lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 35: &lt;/span&gt; Assert.IsFalse(&lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 36: &lt;/span&gt; Assert.IsNull(&lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 37: &lt;/span&gt; Assert.IsNotNull(_invoice);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 38: &lt;/span&gt; Assert.IsEmpty(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 39: &lt;/span&gt; Assert.IsNotEmpty(&lt;span class="str"&gt;"This
string is not empty"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 40: &lt;/span&gt; Assert.Fail(&lt;span class="str"&gt;"This is a failure
message"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 41: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 42: &lt;/span&gt; &lt;span class="rem"&gt;//Expected Exception Test&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 43: &lt;/span&gt; [Test]&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 44: &lt;/span&gt; [ExpectedException(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(System.Security.SecurityException))]&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 45: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DeleteTestNoRights()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 46: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 47: &lt;/span&gt; _invoice.Delete();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 48: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 49: &lt;/span&gt; &lt;span class="rem"&gt;//Not Implemented
Test&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 50: &lt;/span&gt; [Test]&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 51: &lt;/span&gt; [Ignore(&lt;span class="str"&gt;"Please
implement"&lt;/span&gt;)]&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 52: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UpdateTestNoRights()&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 53: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 54: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 55: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 56: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=f0181029-552c-4299-8553-85251afbbcdd" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,f0181029-552c-4299-8553-85251afbbcdd.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=0b56b2ee-b38d-4f8a-9d81-daf98c64c605</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,0b56b2ee-b38d-4f8a-9d81-daf98c64c605.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,0b56b2ee-b38d-4f8a-9d81-daf98c64c605.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0b56b2ee-b38d-4f8a-9d81-daf98c64c605</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In broadcaster
</p>
        <p>
1. Declare a event member.<br />
2. fire the event somewhere
</p>
        <pre class="csharpcode">
          <span class="kwrd">public</span>
          <span class="kwrd">class</span> PriceChangedEventArgs
: System.EventArgs { <span class="kwrd">public</span><span class="kwrd">readonly</span><span class="kwrd">decimal</span> LastPrice; <span class="kwrd">public</span><span class="kwrd">readonly</span><span class="kwrd">decimal</span> NewPrice; <span class="kwrd">public</span> PriceChangedEventArgs
(<span class="kwrd">decimal</span> lastPrice, <span class="kwrd">decimal</span> newPrice)
{ LastPrice = lastPrice; NewPrice = newPrice; } } </pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <pre class="csharpcode">
          <span class="kwrd">public</span>
          <span class="kwrd">class</span> Stock
{ ... <span class="kwrd">public</span><span class="kwrd">event</span> EventHandler&lt;PriceChangedEventArgs&gt;
PriceChanged; <span class="kwrd">protected</span><span class="kwrd">virtual</span><span class="kwrd">void</span> OnPriceChanged
(PriceChangedEventArgs e) { <span class="kwrd">if</span> (PriceChanged != <span class="kwrd">null</span>)
PriceChanged (<span class="kwrd">this</span>, e); } } </pre>
        <p>
 
</p>
        <pre class="csharpcode">
          <span class="kwrd">class</span> Test { <span class="kwrd">static</span><span class="kwrd">void</span> Main(
) { Stock stock = <span class="kwrd">new</span> Stock (<span class="str">"THPW"</span>);
stock.Price = 27.10M; <span class="rem">// register with the PriceChanged event</span> stock.PriceChanged
+= stock_PriceChanged; stock.Price = 31.59M; } <span class="kwrd">static</span><span class="kwrd">void</span> stock_PriceChanged
(<span class="kwrd">object</span> sender, PriceChangedEventArgs e) { <span class="kwrd">if</span> ((e.NewPrice
- e.LastPrice) / e.LastPrice &gt; 0.1M) Console.WriteLine (<span class="str">"Alert,
10% stock price increase!"</span>); } } </pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
More information, please refer to 
<br /><a title="http://www.akadia.com/services/dotnet_delegates_and_events.html" href="http://www.akadia.com/services/dotnet_delegates_and_events.html">http://www.akadia.com/services/dotnet_delegates_and_events.html</a></p>
        <p>
A example of delegate
</p>
        <pre class="csharpcode">
          <span class="kwrd">using</span> System; <span class="kwrd">namespace</span> Akadia.SimpleDelegate
{ <span class="rem">// Delegate Specification</span><span class="kwrd">public</span><span class="kwrd">class</span> MyClass
{ <span class="rem">// Declare a delegate that takes a single string parameter</span><span class="rem">//
and has no return type.</span><span class="kwrd">public</span><span class="kwrd">delegate</span><span class="kwrd">void</span> LogHandler(<span class="kwrd">string</span> message); <span class="rem">//
The use of the delegate is just like calling a function directly,</span><span class="rem">//
though we need to add a check to see if the delegate is null</span><span class="rem">//
(that is, not pointing to a function) before calling the function.</span><span class="kwrd">public</span><span class="kwrd">void</span> Process(LogHandler
logHandler) { <span class="kwrd">if</span> (logHandler != <span class="kwrd">null</span>)
{ logHandler(<span class="str">"Process() begin"</span>); } <span class="kwrd">if</span> (logHandler
!= <span class="kwrd">null</span>) { logHandler (<span class="str">"Process() end"</span>);
} } } <span class="rem">// Test Application to use the defined Delegate</span><span class="kwrd">public</span><span class="kwrd">class</span> TestApplication
{ <span class="rem">// Static Function: To which is used in the Delegate. To call
the Process()</span><span class="rem">// function, we need to declare a logging function:
Logger() that matches</span><span class="rem">// the signature of the delegate.</span><span class="kwrd">static</span><span class="kwrd">void</span> Logger(<span class="kwrd">string</span> s)
{ Console.WriteLine(s); } <span class="kwrd">static</span><span class="kwrd">void</span> Main(<span class="kwrd">string</span>[]
args) { MyClass myClass = <span class="kwrd">new</span> MyClass(); <span class="rem">//
Crate an instance of the delegate, pointing to the logging function.</span><span class="rem">//
This delegate will then be passed to the Process() function.</span> MyClass.LogHandler
myLogger = <span class="kwrd">new</span> MyClass.LogHandler(Logger); myClass.Process(myLogger);
} } } </pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=0b56b2ee-b38d-4f8a-9d81-daf98c64c605" />
      </body>
      <title>Steps to define and consume a event in .Net</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,0b56b2ee-b38d-4f8a-9d81-daf98c64c605.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,0b56b2ee-b38d-4f8a-9d81-daf98c64c605.aspx</link>
      <pubDate>Tue, 06 Apr 2010 19:10:01 GMT</pubDate>
      <description>&lt;p&gt;
In broadcaster
&lt;/p&gt;
&lt;p&gt;
1. Declare a event member.&lt;br&gt;
2. fire the event somewhere
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; PriceChangedEventArgs
: System.EventArgs { &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;decimal&lt;/span&gt; LastPrice; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;decimal&lt;/span&gt; NewPrice; &lt;span class="kwrd"&gt;public&lt;/span&gt; PriceChangedEventArgs
(&lt;span class="kwrd"&gt;decimal&lt;/span&gt; lastPrice, &lt;span class="kwrd"&gt;decimal&lt;/span&gt; newPrice)
{ LastPrice = lastPrice; NewPrice = newPrice; } } &lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Stock
{ ... &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; EventHandler&amp;lt;PriceChangedEventArgs&amp;gt;
PriceChanged; &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPriceChanged
(PriceChangedEventArgs e) { &lt;span class="kwrd"&gt;if&lt;/span&gt; (PriceChanged != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
PriceChanged (&lt;span class="kwrd"&gt;this&lt;/span&gt;, e); } } &lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Test { &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(
) { Stock stock = &lt;span class="kwrd"&gt;new&lt;/span&gt; Stock (&lt;span class="str"&gt;"THPW"&lt;/span&gt;);
stock.Price = 27.10M; &lt;span class="rem"&gt;// register with the PriceChanged event&lt;/span&gt; stock.PriceChanged
+= stock_PriceChanged; stock.Price = 31.59M; } &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; stock_PriceChanged
(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, PriceChangedEventArgs e) { &lt;span class="kwrd"&gt;if&lt;/span&gt; ((e.NewPrice
- e.LastPrice) / e.LastPrice &amp;gt; 0.1M) Console.WriteLine (&lt;span class="str"&gt;"Alert,
10% stock price increase!"&lt;/span&gt;); } } &lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
More information, please refer to 
&lt;br&gt;
&lt;a title="http://www.akadia.com/services/dotnet_delegates_and_events.html" href="http://www.akadia.com/services/dotnet_delegates_and_events.html"&gt;http://www.akadia.com/services/dotnet_delegates_and_events.html&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
A example of delegate
&lt;/p&gt;
&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; System; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; Akadia.SimpleDelegate
{ &lt;span class="rem"&gt;// Delegate Specification&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyClass
{ &lt;span class="rem"&gt;// Declare a delegate that takes a single string parameter&lt;/span&gt; &lt;span class="rem"&gt;//
and has no return type.&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; LogHandler(&lt;span class="kwrd"&gt;string&lt;/span&gt; message); &lt;span class="rem"&gt;//
The use of the delegate is just like calling a function directly,&lt;/span&gt; &lt;span class="rem"&gt;//
though we need to add a check to see if the delegate is null&lt;/span&gt; &lt;span class="rem"&gt;//
(that is, not pointing to a function) before calling the function.&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Process(LogHandler
logHandler) { &lt;span class="kwrd"&gt;if&lt;/span&gt; (logHandler != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{ logHandler(&lt;span class="str"&gt;"Process() begin"&lt;/span&gt;); } &lt;span class="kwrd"&gt;if&lt;/span&gt; (logHandler
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;) { logHandler (&lt;span class="str"&gt;"Process() end"&lt;/span&gt;);
} } } &lt;span class="rem"&gt;// Test Application to use the defined Delegate&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TestApplication
{ &lt;span class="rem"&gt;// Static Function: To which is used in the Delegate. To call
the Process()&lt;/span&gt; &lt;span class="rem"&gt;// function, we need to declare a logging function:
Logger() that matches&lt;/span&gt; &lt;span class="rem"&gt;// the signature of the delegate.&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Logger(&lt;span class="kwrd"&gt;string&lt;/span&gt; s)
{ Console.WriteLine(s); } &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[]
args) { MyClass myClass = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyClass(); &lt;span class="rem"&gt;//
Crate an instance of the delegate, pointing to the logging function.&lt;/span&gt; &lt;span class="rem"&gt;//
This delegate will then be passed to the Process() function.&lt;/span&gt; MyClass.LogHandler
myLogger = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyClass.LogHandler(Logger); myClass.Process(myLogger);
} } } &lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=0b56b2ee-b38d-4f8a-9d81-daf98c64c605" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,0b56b2ee-b38d-4f8a-9d81-daf98c64c605.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=e5808029-352e-46b4-87c6-b5ff6d269d45</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,e5808029-352e-46b4-87c6-b5ff6d269d45.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,e5808029-352e-46b4-87c6-b5ff6d269d45.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e5808029-352e-46b4-87c6-b5ff6d269d45</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="2">An application domain is a logical container that </font>
          <font size="2">
            <strong>allows
multiple assemblies to run<br />
within a single process but prevents them from directly accessing other assemblies’<br />
memories.</strong> Application domains offer many of the features of a process, such
as separate<br />
memory spaces and access to resources. However, application domains are more<br />
efficient than processes, enabling multiple assemblies to be run in separate application<br />
domains without the overhead of launching separate processes. Figure 8-1 shows<br />
how a single process can contain multiple application domains.</font>
        </p>
        <p>
          <font size="2">
          </font>  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ApplicationDomain_D156/image_2.png">
            <font color="#000000" size="2">
              <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ApplicationDomain_D156/image_thumb.png" width="510" height="256" />
            </font>
          </a>
          <font size="2">
          </font>
        </p>
        <p>
          <font size="2">
          </font>  
</p>
        <p>
          <font size="2">The best example of application domains in use is Internet Information
Services (IIS)<br />
5.0’s ASP.NET worker process, implemented by Aspnet_wp.exe. If 10 people visit an<br />
ASP.NET Web site simultaneously, ASP.NET will create a separate application domain<br />
for each user. Essentially, ASP.NET runs 10 separate instances of the assembly.<br />
Each instance of the assembly can store a property called userName without any concern<br />
that other instances will be able to access or overwrite the contents of the property.<br />
This same effect could be achieved by launching the same assembly in 10<br />
separate processes, but switching between the processes would consume processor<br />
time, thus decreasing performance.<br />
Most of the time, you will rely on the existing run-time hosts to automatically create<br />
application domains for your assemblies. Examples of run-time hosts built into<br />
Microsoft Windows are ASP.NET, Internet Explorer (which creates a single application<br />
domain for all assemblies from a specific Web site), and the operating system. You
can<br />
configure the behavior of these application domains by using friendly tools such as
the<br />
Internet Information Services Manager and the .NET Framework Configuration tool.<br />
However, just as Aspnet_wp.exe creates application domains to isolate multiple instances<br />
of an assembly, you can create your own application domains to call assemblies with
little<br />
risk that the assembly will take any action or access any resources that you have
not specifically<br />
permitted. Figure 8-2 shows how an assembly can host application domains.</font>
        </p>
        <p>
          <font size="2">
          </font>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=e5808029-352e-46b4-87c6-b5ff6d269d45" />
      </body>
      <title>Application Domain</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,e5808029-352e-46b4-87c6-b5ff6d269d45.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,e5808029-352e-46b4-87c6-b5ff6d269d45.aspx</link>
      <pubDate>Tue, 06 Apr 2010 18:53:16 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="2"&gt;An application domain is a logical container that &lt;/font&gt;&lt;font size="2"&gt;&lt;strong&gt;allows
multiple assemblies to run&lt;br&gt;
within a single process but prevents them from directly accessing other assemblies’&lt;br&gt;
memories.&lt;/strong&gt; Application domains offer many of the features of a process, such
as separate&lt;br&gt;
memory spaces and access to resources. However, application domains are more&lt;br&gt;
efficient than processes, enabling multiple assemblies to be run in separate application&lt;br&gt;
domains without the overhead of launching separate processes. Figure 8-1 shows&lt;br&gt;
how a single process can contain multiple application domains.&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ApplicationDomain_D156/image_2.png"&gt;&lt;font color="#000000" size="2"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ApplicationDomain_D156/image_thumb.png" width="510" height="256"&gt;&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; &lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;&amp;nbsp; 
&lt;p&gt;
&lt;font size="2"&gt;The best example of application domains in use is Internet Information
Services (IIS)&lt;br&gt;
5.0’s ASP.NET worker process, implemented by Aspnet_wp.exe. If 10 people visit an&lt;br&gt;
ASP.NET Web site simultaneously, ASP.NET will create a separate application domain&lt;br&gt;
for each user. Essentially, ASP.NET runs 10 separate instances of the assembly.&lt;br&gt;
Each instance of the assembly can store a property called userName without any concern&lt;br&gt;
that other instances will be able to access or overwrite the contents of the property.&lt;br&gt;
This same effect could be achieved by launching the same assembly in 10&lt;br&gt;
separate processes, but switching between the processes would consume processor&lt;br&gt;
time, thus decreasing performance.&lt;br&gt;
Most of the time, you will rely on the existing run-time hosts to automatically create&lt;br&gt;
application domains for your assemblies. Examples of run-time hosts built into&lt;br&gt;
Microsoft Windows are ASP.NET, Internet Explorer (which creates a single application&lt;br&gt;
domain for all assemblies from a specific Web site), and the operating system. You
can&lt;br&gt;
configure the behavior of these application domains by using friendly tools such as
the&lt;br&gt;
Internet Information Services Manager and the .NET Framework Configuration tool.&lt;br&gt;
However, just as Aspnet_wp.exe creates application domains to isolate multiple instances&lt;br&gt;
of an assembly, you can create your own application domains to call assemblies with
little&lt;br&gt;
risk that the assembly will take any action or access any resources that you have
not specifically&lt;br&gt;
permitted. Figure 8-2 shows how an assembly can host application domains.&lt;/font&gt; 
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=e5808029-352e-46b4-87c6-b5ff6d269d45" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,e5808029-352e-46b4-87c6-b5ff6d269d45.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.dotnetfunda.com/interview/ShowCatQuestion.aspx?category=34" href="http://www.dotnetfunda.com/interview/ShowCatQuestion.aspx?category=34">http://www.dotnetfunda.com/interview/ShowCatQuestion.aspx?category=34</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a" />
      </body>
      <title>Interview Resources</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a.aspx</link>
      <pubDate>Mon, 29 Mar 2010 04:05:49 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://www.dotnetfunda.com/interview/ShowCatQuestion.aspx?category=34" href="http://www.dotnetfunda.com/interview/ShowCatQuestion.aspx?category=34"&gt;http://www.dotnetfunda.com/interview/ShowCatQuestion.aspx?category=34&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,bf2451c3-6dfe-41b5-b2da-e6c08bf38a3a.aspx</comments>
      <category>DotNet;Life / Career</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=7ff0a174-37a0-4056-b0cf-f9acc5595c54</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,7ff0a174-37a0-4056-b0cf-f9acc5595c54.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,7ff0a174-37a0-4056-b0cf-f9acc5595c54.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7ff0a174-37a0-4056-b0cf-f9acc5595c54</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
From book “Code leader using people tools and processes to build successful software”
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb.png" width="244" height="130" />
          </a>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb_1.png" width="126" height="244" />
          </a>  
</p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_6.png">
          <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb_2.png" width="381" height="287" />
        </a>
        <p>
 
</p>
        <p>
The trickiest part of the MVP design process is the View. It must represent all of
the interaction you will<br />
have with your user, using display-agnostic data types. The View, in essence, forms
your application’s<br />
contract with what is ‘‘on the glass’’ or visible to the user on their monitor. If
you are following a TDD<br />
development process, your View is likely to change and evolve during the course of
development, as<br />
requirements become more apparent. That should be easy to do if the proper separation
between View<br />
and Presenter is maintained, although a little refactoring along the way never hurt
anyone.
</p>
        <p>
In most languages, it is easiest to represent your View as an <strong>interface</strong>.
The concrete class directly responsible<br />
for display will implement the View interface. When you write your test code, you
can create another<br />
implementation of the View interface for testing purposes that has no actual user
interface elements<br />
associated with it.
</p>
        <p>
There is one major decision to make before starting work on your View interface. Will
your View expose<br />
events directly? Or will it call the Presenter to report user activity? This is often
debated when starting an<br />
MVP project, and there are adherents in both camps. To put the cards on the table
up front, I personally<br />
favor the former from an architectural perspective. It offers the cleanest separation
between View and<br />
Presenter because the View need know nothing at all about the Presenter. It only receives
data pushed to<br />
it and fires events that represent user actions. From a practical standpoint, however,
there are cons. Using<br />
events may be difficult in some implementation environments. Specifically in a web
application, it may<br />
be difficult for your server ‘‘page’’ to fire events, and just as difficult for your
Presenter to subscribe to<br />
them. It can be much easier in such an application to provide the View with direct
access to the Presenter<br />
so that user events can be reported directly as method calls. That potentially makes
it easier to deal with<br />
the issue of display-agnostic data types as well. If your View’s user interface element
(a button, say) fires<br />
events, and the View has to catch those events, translate from display data types
to neutral data types,<br />
and then fire a second event, the code could become quite cumbersome. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb_3.png" width="297" height="216" />
          </a>
        </p>
        <p>
  
</p>
        <p>
Method 1 
</p>
        <p>
  
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">interface</span> ISurveyView</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span> List&lt;<span class="kwrd">string</span>&gt;
Users { get; set; }</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">bool</span> Question1 { get;
set; }</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">string</span> Question2
{ get; set; }</pre>
          <pre>
            <span class="lnum"> 6: </span>}</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">class</span> SurveyPresenter</pre>
          <pre>
            <span class="lnum"> 8: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 9: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">static</span> Dictionary&lt;ISurveyView,
SurveyPresenter&gt; _presenters =</pre>
          <pre>
            <span class="lnum"> 10: </span>
            <span class="kwrd">new</span> Dictionary&lt;ISurveyView,
SurveyPresenter&gt;();</pre>
          <pre class="alt">
            <span class="lnum"> 11: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">static</span>
            <span class="kwrd">readonly</span>
            <span class="kwrd">object</span> lockObject
= <span class="kwrd">new</span><span class="kwrd">object</span>();</pre>
          <pre>
            <span class="lnum"> 12: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span> SurveyPresenter
Instance(ISurveyView view)</pre>
          <pre class="alt">
            <span class="lnum"> 13: </span> {</pre>
          <pre>
            <span class="lnum"> 14: </span>
            <span class="kwrd">lock</span> (lockObject)</pre>
          <pre class="alt">
            <span class="lnum"> 15: </span> {</pre>
          <pre>
            <span class="lnum"> 16: </span>
            <span class="kwrd">if</span> (!_presenters.ContainsKey(view))</pre>
          <pre class="alt">
            <span class="lnum"> 17: </span> _presenters[view] = <span class="kwrd">new</span> SurveyPresenter(view);</pre>
          <pre>
            <span class="lnum"> 18: </span>
            <span class="kwrd">return</span> _presenters[view];</pre>
          <pre class="alt">
            <span class="lnum"> 19: </span> }</pre>
          <pre>
            <span class="lnum"> 20: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 21: </span> ISurveyView _view;</pre>
          <pre>
            <span class="lnum"> 22: </span>
            <span class="kwrd">private</span> SurveyPresenter(ISurveyView
view)</pre>
          <pre class="alt">
            <span class="lnum"> 23: </span> {</pre>
          <pre>
            <span class="lnum"> 24: </span> _view = view;</pre>
          <pre class="alt">
            <span class="lnum"> 25: </span> }</pre>
          <pre>
            <span class="lnum"> 26: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> OnLoad()</pre>
          <pre class="alt">
            <span class="lnum"> 27: </span>{</pre>
          <pre>
            <span class="lnum"> 28: </span>
            <span class="rem">//this is where you would go
to the</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 29: </span>
            <span class="rem">//model for data,
but we’ll cheat</span>
          </pre>
          <pre>
            <span class="lnum"> 30: </span>List&lt;<span class="kwrd">string</span>&gt; users
= <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;(<span class="kwrd">new</span><span class="kwrd">string</span>[]
i</pre>
          <pre class="alt">
            <span class="lnum"> 31: </span>{ <span class="str">"Fred"</span>, <span class="str">"Bob"</span>, <span class="str">"Patty"</span> });</pre>
          <pre>
            <span class="lnum"> 32: </span>_view.Users = users;</pre>
          <pre class="alt">
            <span class="lnum"> 33: </span>}</pre>
          <pre>
            <span class="lnum"> 34: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> SelectedIndexChanged(<span class="kwrd">int</span> index)</pre>
          <pre class="alt">
            <span class="lnum"> 35: </span> {</pre>
          <pre>
            <span class="lnum"> 36: </span>
            <span class="rem">//go to the model and get answers
for questions</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 37: </span>
            <span class="rem">//we’ll make it
up</span>
          </pre>
          <pre>
            <span class="lnum"> 38: </span>
            <span class="rem">//this is also where the answers
to the previous</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 39: </span>
            <span class="rem">//questions would
be saved back to the model</span>
          </pre>
          <pre>
            <span class="lnum"> 40: </span> _view.Question1 = <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 41: </span> _view.Question2 = <span class="kwrd">string</span>.Format(<span class="str">"{0}
is cool!"</span>, _view.Users[index]);</pre>
          <pre>
            <span class="lnum"> 42: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 43: </span>}</pre>
          <pre>
            <span class="lnum"> 44: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 45: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">partial</span>
            <span class="kwrd">class</span> MvpMain
: Form, ISurveyView</pre>
          <pre>
            <span class="lnum"> 46: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 47: </span>
            <span class="kwrd">public</span> MvpMain()</pre>
          <pre>
            <span class="lnum"> 48: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 49: </span> InitializeComponent();</pre>
          <pre>
            <span class="lnum"> 50: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 51: </span>
            <span class="kwrd">private</span> SurveyPresenter
_presenter;</pre>
          <pre>
            <span class="lnum"> 52: </span>
            <span class="preproc">#region</span> ISurveyView
Members</pre>
          <pre class="alt">
            <span class="lnum"> 53: </span>
            <span class="kwrd">public</span> List&lt;<span class="kwrd">string</span>&gt;
Users</pre>
          <pre>
            <span class="lnum"> 54: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 55: </span> get</pre>
          <pre>
            <span class="lnum"> 56: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 57: </span> List&lt;<span class="kwrd">string</span>&gt;
users = <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;();</pre>
          <pre>
            <span class="lnum"> 58: </span>
            <span class="kwrd">foreach</span> (<span class="kwrd">object</span> item <span class="kwrd">in</span> userList.Items)</pre>
          <pre class="alt">
            <span class="lnum"> 59: </span> {</pre>
          <pre>
            <span class="lnum"> 60: </span> users.Add((<span class="kwrd">string</span>)item);</pre>
          <pre class="alt">
            <span class="lnum"> 61: </span> }</pre>
          <pre>
            <span class="lnum"> 62: </span>
            <span class="kwrd">return</span> users;</pre>
          <pre class="alt">
            <span class="lnum"> 63: </span> }</pre>
          <pre>
            <span class="lnum"> 64: </span> set</pre>
          <pre class="alt">
            <span class="lnum"> 65: </span> {</pre>
          <pre>
            <span class="lnum"> 66: </span> userList.Items.Clear();</pre>
          <pre class="alt">
            <span class="lnum"> 67: </span>
            <span class="kwrd">foreach</span> (<span class="kwrd">string</span> user <span class="kwrd">in</span><span class="kwrd">value</span>)</pre>
          <pre>
            <span class="lnum"> 68: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 69: </span> userList.Items.Add(user);</pre>
          <pre>
            <span class="lnum"> 70: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 71: </span> }</pre>
          <pre>
            <span class="lnum"> 72: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 73: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">bool</span> Question1</pre>
          <pre>
            <span class="lnum"> 74: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 75: </span> get</pre>
          <pre>
            <span class="lnum"> 76: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 77: </span>
            <span class="kwrd">if</span> (yesButton.Checked)</pre>
          <pre>
            <span class="lnum"> 78: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 79: </span>
            <span class="kwrd">else</span>
          </pre>
          <pre>
            <span class="lnum"> 80: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">false</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 81: </span> }</pre>
          <pre>
            <span class="lnum"> 82: </span> set</pre>
          <pre class="alt">
            <span class="lnum"> 83: </span> {</pre>
          <pre>
            <span class="lnum"> 84: </span>
            <span class="kwrd">if</span> (<span class="kwrd">value</span>)</pre>
          <pre class="alt">
            <span class="lnum"> 85: </span> {</pre>
          <pre>
            <span class="lnum"> 86: </span> yesButton.Checked = <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 87: </span> noButton.Checked = <span class="kwrd">false</span>;</pre>
          <pre>
            <span class="lnum"> 88: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 89: </span>
            <span class="kwrd">else</span>
          </pre>
          <pre>
            <span class="lnum"> 90: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 91: </span> yesButton.Checked = <span class="kwrd">false</span>;</pre>
          <pre>
            <span class="lnum"> 92: </span> noButton.Checked = <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 93: </span> }</pre>
          <pre>
            <span class="lnum"> 94: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 95: </span> }</pre>
          <pre>
            <span class="lnum"> 96: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">string</span> Question2</pre>
          <pre class="alt">
            <span class="lnum"> 97: </span> {</pre>
          <pre>
            <span class="lnum"> 98: </span> get</pre>
          <pre class="alt">
            <span class="lnum"> 99: </span> {</pre>
          <pre>
            <span class="lnum"> 100: </span>
            <span class="kwrd">return</span> question2Box.Text;</pre>
          <pre class="alt">
            <span class="lnum"> 101: </span> }</pre>
          <pre>
            <span class="lnum"> 102: </span> set</pre>
          <pre class="alt">
            <span class="lnum"> 103: </span> {</pre>
          <pre>
            <span class="lnum"> 104: </span> question2Box.Text = <span class="kwrd">value</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 105: </span> }</pre>
          <pre>
            <span class="lnum"> 106: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 107: </span>
            <span class="preproc">#endregion</span>
          </pre>
          <pre>
            <span class="lnum"> 108: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">void</span> MvpMain_Load(<span class="kwrd">object</span> sender,
EventArgs e)</pre>
          <pre class="alt">
            <span class="lnum"> 109: </span> {</pre>
          <pre>
            <span class="lnum"> 110: </span> _presenter = SurveyPresenter.Instance(<span class="kwrd">this</span>);</pre>
          <pre class="alt">
            <span class="lnum"> 111: </span> _presenter.OnLoad();</pre>
          <pre>
            <span class="lnum"> 112: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 113: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">void</span> userList_SelectedIndexChanged(<span class="kwrd">object</span> sender,
EventArgs e)</pre>
          <pre>
            <span class="lnum"> 114: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 115: </span> _presenter.SelectedIndexChanged(userList.SelectedIndex);</pre>
          <pre>
            <span class="lnum"> 116: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 117: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
Method 2
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">interface</span> ISurveyView</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span> List&lt;<span class="kwrd">string</span>&gt;
Users { get; set; }</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">bool</span> Question1 { get;
set; }</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">string</span> Question2
{ get; set; }</pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">event</span> SelectionChangedDelegate
SelectionChanged;</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>
            <span class="kwrd">event</span> OnLoadDelegate
OnLoad;</pre>
          <pre>
            <span class="lnum"> 8: </span>}</pre>
          <pre class="alt">
            <span class="lnum"> 9: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">delegate</span>
            <span class="kwrd">void</span> SelectionChangedDelegate(<span class="kwrd">int</span> index);</pre>
          <pre>
            <span class="lnum"> 10: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">delegate</span>
            <span class="kwrd">void</span> OnLoadDelegate();</pre>
          <pre class="alt">
            <span class="lnum"> 11: </span> </pre>
          <pre>
            <span class="lnum"> 12: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">class</span> SurveyPresenter</pre>
          <pre class="alt">
            <span class="lnum"> 13: </span>{</pre>
          <pre>
            <span class="lnum"> 14: </span> ISurveyView _view;</pre>
          <pre class="alt">
            <span class="lnum"> 15: </span>
            <span class="kwrd">public</span> SurveyPresenter(ISurveyView
view)</pre>
          <pre>
            <span class="lnum"> 16: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 17: </span>_view = view;</pre>
          <pre>
            <span class="lnum"> 18: </span>_view.OnLoad += <span class="kwrd">new</span> OnLoadDelegate(OnLoad);</pre>
          <pre class="alt">
            <span class="lnum"> 19: </span>_view.SelectionChanged += <span class="kwrd">new</span> i</pre>
          <pre>
            <span class="lnum"> 20: </span>SelectionChangedDelegate(SelectedIndexChanged);</pre>
          <pre class="alt">
            <span class="lnum"> 21: </span>}</pre>
          <pre>
            <span class="lnum"> 22: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> OnLoad()</pre>
          <pre class="alt">
            <span class="lnum"> 23: </span>{</pre>
          <pre>
            <span class="lnum"> 24: </span>
            <span class="rem">//this is where you would go
to the</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 25: </span>
            <span class="rem">//model for data,
but we’ll cheat</span>
          </pre>
          <pre>
            <span class="lnum"> 26: </span>List&lt;<span class="kwrd">string</span>&gt; users
= <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;(<span class="kwrd">new</span><span class="kwrd">string</span>[]
i</pre>
          <pre class="alt">
            <span class="lnum"> 27: </span>{ <span class="str">"Fred"</span>, <span class="str">"Bob"</span>, <span class="str">"Patty"</span> });</pre>
          <pre>
            <span class="lnum"> 28: </span>_view.Users = users;</pre>
          <pre class="alt">
            <span class="lnum"> 29: </span>}</pre>
          <pre>
            <span class="lnum"> 30: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> SelectedIndexChanged(<span class="kwrd">int</span> index)</pre>
          <pre class="alt">
            <span class="lnum"> 31: </span> {</pre>
          <pre>
            <span class="lnum"> 32: </span>
            <span class="rem">//go to the model and get answers
for questions</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 33: </span>
            <span class="rem">//we’ll make it
up</span>
          </pre>
          <pre>
            <span class="lnum"> 34: </span>
            <span class="rem">//This is also where the answers
to the previous</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 35: </span>
            <span class="rem">//questions would
be saved back to the model.</span>
          </pre>
          <pre>
            <span class="lnum"> 36: </span> _view.Question1 = <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 37: </span> _view.Question2 = <span class="kwrd">string</span>.Format(<span class="str">"{0}
is cool!"</span>, _view.Users[index]);</pre>
          <pre>
            <span class="lnum"> 38: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 39: </span>}</pre>
          <pre>
            <span class="lnum"> 40: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">partial</span>
            <span class="kwrd">class</span> MvpMain
: Form, ISurveyView</pre>
          <pre class="alt">
            <span class="lnum"> 41: </span>{</pre>
          <pre>
            <span class="lnum"> 42: </span>
            <span class="kwrd">public</span> MvpMain()</pre>
          <pre class="alt">
            <span class="lnum"> 43: </span> {</pre>
          <pre>
            <span class="lnum"> 44: </span> InitializeComponent();</pre>
          <pre class="alt">
            <span class="lnum"> 45: </span> _presenter = <span class="kwrd">new</span> SurveyPresenter(<span class="kwrd">this</span>);</pre>
          <pre>
            <span class="lnum"> 46: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 47: </span>
            <span class="kwrd">private</span> SurveyPresenter
_presenter;</pre>
          <pre>
            <span class="lnum"> 48: </span>
            <span class="preproc">#region</span> ISurveyView
Members</pre>
          <pre class="alt">
            <span class="lnum"> 49: </span>
            <span class="kwrd">public</span> List&lt;<span class="kwrd">string</span>&gt;
Users</pre>
          <pre>
            <span class="lnum"> 50: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 51: </span> get</pre>
          <pre>
            <span class="lnum"> 52: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 53: </span> List&lt;<span class="kwrd">string</span>&gt;
users = <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;();</pre>
          <pre>
            <span class="lnum"> 54: </span>
            <span class="kwrd">foreach</span> (<span class="kwrd">object</span> item <span class="kwrd">in</span> userList.Items)</pre>
          <pre class="alt">
            <span class="lnum"> 55: </span> {</pre>
          <pre>
            <span class="lnum"> 56: </span> users.Add((<span class="kwrd">string</span>)item);</pre>
          <pre class="alt">
            <span class="lnum"> 57: </span> }</pre>
          <pre>
            <span class="lnum"> 58: </span>
            <span class="kwrd">return</span> users;</pre>
          <pre class="alt">
            <span class="lnum"> 59: </span> }</pre>
          <pre>
            <span class="lnum"> 60: </span> set</pre>
          <pre class="alt">
            <span class="lnum"> 61: </span> {</pre>
          <pre>
            <span class="lnum"> 62: </span> userList.Items.Clear();</pre>
          <pre class="alt">
            <span class="lnum"> 63: </span>
            <span class="kwrd">foreach</span> (<span class="kwrd">string</span> user <span class="kwrd">in</span><span class="kwrd">value</span>)</pre>
          <pre>
            <span class="lnum"> 64: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 65: </span> userList.Items.Add(user);</pre>
          <pre>
            <span class="lnum"> 66: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 67: </span> }</pre>
          <pre>
            <span class="lnum"> 68: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 69: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">bool</span> Question1</pre>
          <pre>
            <span class="lnum"> 70: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 71: </span> get</pre>
          <pre>
            <span class="lnum"> 72: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 73: </span>
            <span class="kwrd">if</span> (yesButton.Checked)</pre>
          <pre>
            <span class="lnum"> 74: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 75: </span>
            <span class="kwrd">else</span>
          </pre>
          <pre>
            <span class="lnum"> 76: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">false</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 77: </span> }</pre>
          <pre>
            <span class="lnum"> 78: </span> set</pre>
          <pre class="alt">
            <span class="lnum"> 79: </span> {</pre>
          <pre>
            <span class="lnum"> 80: </span>
            <span class="kwrd">if</span> (<span class="kwrd">value</span>)</pre>
          <pre class="alt">
            <span class="lnum"> 81: </span> {</pre>
          <pre>
            <span class="lnum"> 82: </span> yesButton.Checked = <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 83: </span> noButton.Checked = <span class="kwrd">false</span>;</pre>
          <pre>
            <span class="lnum"> 84: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 85: </span>
            <span class="kwrd">else</span>
          </pre>
          <pre>
            <span class="lnum"> 86: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 87: </span> yesButton.Checked = <span class="kwrd">false</span>;</pre>
          <pre>
            <span class="lnum"> 88: </span> noButton.Checked = <span class="kwrd">true</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 89: </span> }</pre>
          <pre>
            <span class="lnum"> 90: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 91: </span> }</pre>
          <pre>
            <span class="lnum"> 92: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">string</span> Question2</pre>
          <pre class="alt">
            <span class="lnum"> 93: </span> {</pre>
          <pre>
            <span class="lnum"> 94: </span> get</pre>
          <pre class="alt">
            <span class="lnum"> 95: </span> {</pre>
          <pre>
            <span class="lnum"> 96: </span>
            <span class="kwrd">return</span> question2Box.Text;</pre>
          <pre class="alt">
            <span class="lnum"> 97: </span> }</pre>
          <pre>
            <span class="lnum"> 98: </span> set</pre>
          <pre class="alt">
            <span class="lnum"> 99: </span> {</pre>
          <pre>
            <span class="lnum"> 100: </span> question2Box.Text = <span class="kwrd">value</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 101: </span> }</pre>
          <pre>
            <span class="lnum"> 102: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 103: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">event</span> OnLoadDelegate
OnLoad;</pre>
          <pre>
            <span class="lnum"> 104: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">event</span> SelectionChangedDelegate
SelectionChanged;</pre>
          <pre class="alt">
            <span class="lnum"> 105: </span>
            <span class="preproc">#endregion</span>
          </pre>
          <pre>
            <span class="lnum"> 106: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">void</span> MvpMain_Load(<span class="kwrd">object</span> sender,
EventArgs e)</pre>
          <pre class="alt">
            <span class="lnum"> 107: </span> {</pre>
          <pre>
            <span class="lnum"> 108: </span>
            <span class="kwrd">if</span> (OnLoad != <span class="kwrd">null</span>)</pre>
          <pre class="alt">
            <span class="lnum"> 109: </span> OnLoad();</pre>
          <pre>
            <span class="lnum"> 110: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 111: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">void</span> userList_SelectedIndexChanged(<span class="kwrd">object</span> sender,
EventArgs e)</pre>
          <pre>
            <span class="lnum"> 112: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 113: </span>
            <span class="kwrd">if</span> (SelectionChanged
!= <span class="kwrd">null</span>)</pre>
          <pre>
            <span class="lnum"> 114: </span> SelectionChanged(userList.SelectedIndex);</pre>
          <pre class="alt">
            <span class="lnum"> 115: </span> }</pre>
          <pre>
            <span class="lnum"> 116: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=7ff0a174-37a0-4056-b0cf-f9acc5595c54" />
      </body>
      <title>Model-View-Presenter</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,7ff0a174-37a0-4056-b0cf-f9acc5595c54.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,7ff0a174-37a0-4056-b0cf-f9acc5595c54.aspx</link>
      <pubDate>Thu, 25 Mar 2010 20:56:58 GMT</pubDate>
      <description>&lt;p&gt;
From book “Code leader using people tools and processes to build successful software”
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb.png" width="244" height="130"&gt;&lt;/a&gt; &lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb_1.png" width="126" height="244"&gt;&lt;/a&gt;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb_2.png" width="381" height="287"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The trickiest part of the MVP design process is the View. It must represent all of
the interaction you will&lt;br&gt;
have with your user, using display-agnostic data types. The View, in essence, forms
your application’s&lt;br&gt;
contract with what is ‘‘on the glass’’ or visible to the user on their monitor. If
you are following a TDD&lt;br&gt;
development process, your View is likely to change and evolve during the course of
development, as&lt;br&gt;
requirements become more apparent. That should be easy to do if the proper separation
between View&lt;br&gt;
and Presenter is maintained, although a little refactoring along the way never hurt
anyone.
&lt;/p&gt;
&lt;p&gt;
In most languages, it is easiest to represent your View as an &lt;strong&gt;interface&lt;/strong&gt;.
The concrete class directly responsible&lt;br&gt;
for display will implement the View interface. When you write your test code, you
can create another&lt;br&gt;
implementation of the View interface for testing purposes that has no actual user
interface elements&lt;br&gt;
associated with it.
&lt;/p&gt;
&lt;p&gt;
There is one major decision to make before starting work on your View interface. Will
your View expose&lt;br&gt;
events directly? Or will it call the Presenter to report user activity? This is often
debated when starting an&lt;br&gt;
MVP project, and there are adherents in both camps. To put the cards on the table
up front, I personally&lt;br&gt;
favor the former from an architectural perspective. It offers the cleanest separation
between View and&lt;br&gt;
Presenter because the View need know nothing at all about the Presenter. It only receives
data pushed to&lt;br&gt;
it and fires events that represent user actions. From a practical standpoint, however,
there are cons. Using&lt;br&gt;
events may be difficult in some implementation environments. Specifically in a web
application, it may&lt;br&gt;
be difficult for your server ‘‘page’’ to fire events, and just as difficult for your
Presenter to subscribe to&lt;br&gt;
them. It can be much easier in such an application to provide the View with direct
access to the Presenter&lt;br&gt;
so that user events can be reported directly as method calls. That potentially makes
it easier to deal with&lt;br&gt;
the issue of display-agnostic data types as well. If your View’s user interface element
(a button, say) fires&lt;br&gt;
events, and the View has to catch those events, translate from display data types
to neutral data types,&lt;br&gt;
and then fire a second event, the code could become quite cumbersome. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ModelViewPresenter_EECC/image_thumb_3.png" width="297" height="216"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Method 1 
&lt;p&gt;
&amp;nbsp; 
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ISurveyView&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
Users { get; set; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Question1 { get;
set; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Question2
{ get; set; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SurveyPresenter&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Dictionary&amp;lt;ISurveyView,
SurveyPresenter&amp;gt; _presenters =&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;ISurveyView,
SurveyPresenter&amp;gt;();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; lockObject
= &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; SurveyPresenter
Instance(ISurveyView view)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; &lt;span class="kwrd"&gt;lock&lt;/span&gt; (lockObject)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (!_presenters.ContainsKey(view))&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; _presenters[view] = &lt;span class="kwrd"&gt;new&lt;/span&gt; SurveyPresenter(view);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; _presenters[view];&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt; ISurveyView _view;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 22: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; SurveyPresenter(ISurveyView
view)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 23: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 24: &lt;/span&gt; _view = view;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 25: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 26: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnLoad()&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 27: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 28: &lt;/span&gt;&lt;span class="rem"&gt;//this is where you would go
to the&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 29: &lt;/span&gt;&lt;span class="rem"&gt;//model for data,
but we’ll cheat&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 30: &lt;/span&gt;List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; users
= &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[]
i&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 31: &lt;/span&gt;{ &lt;span class="str"&gt;"Fred"&lt;/span&gt;, &lt;span class="str"&gt;"Bob"&lt;/span&gt;, &lt;span class="str"&gt;"Patty"&lt;/span&gt; });&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 32: &lt;/span&gt;_view.Users = users;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 33: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 34: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SelectedIndexChanged(&lt;span class="kwrd"&gt;int&lt;/span&gt; index)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 35: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 36: &lt;/span&gt; &lt;span class="rem"&gt;//go to the model and get answers
for questions&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 37: &lt;/span&gt; &lt;span class="rem"&gt;//we’ll make it
up&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 38: &lt;/span&gt; &lt;span class="rem"&gt;//this is also where the answers
to the previous&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 39: &lt;/span&gt; &lt;span class="rem"&gt;//questions would
be saved back to the model&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 40: &lt;/span&gt; _view.Question1 = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 41: &lt;/span&gt; _view.Question2 = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0}
is cool!"&lt;/span&gt;, _view.Users[index]);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 42: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 43: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 44: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 45: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MvpMain
: Form, ISurveyView&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 46: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 47: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; MvpMain()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 48: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 49: &lt;/span&gt; InitializeComponent();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 50: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 51: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; SurveyPresenter
_presenter;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 52: &lt;/span&gt; &lt;span class="preproc"&gt;#region&lt;/span&gt; ISurveyView
Members&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 53: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
Users&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 54: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 55: &lt;/span&gt; get&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 56: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 57: &lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
users = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 58: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;object&lt;/span&gt; item &lt;span class="kwrd"&gt;in&lt;/span&gt; userList.Items)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 59: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 60: &lt;/span&gt; users.Add((&lt;span class="kwrd"&gt;string&lt;/span&gt;)item);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 61: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 62: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; users;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 63: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 64: &lt;/span&gt; set&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 65: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 66: &lt;/span&gt; userList.Items.Clear();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 67: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; user &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 68: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 69: &lt;/span&gt; userList.Items.Add(user);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 70: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 71: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 72: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 73: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Question1&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 74: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 75: &lt;/span&gt; get&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 76: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 77: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (yesButton.Checked)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 78: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 79: &lt;/span&gt; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 80: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 81: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 82: &lt;/span&gt; set&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 83: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 84: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 85: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 86: &lt;/span&gt; yesButton.Checked = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 87: &lt;/span&gt; noButton.Checked = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 88: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 89: &lt;/span&gt; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 90: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 91: &lt;/span&gt; yesButton.Checked = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 92: &lt;/span&gt; noButton.Checked = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 93: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 94: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 95: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 96: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Question2&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 97: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 98: &lt;/span&gt; get&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 99: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 100: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; question2Box.Text;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 101: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 102: &lt;/span&gt; set&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 103: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 104: &lt;/span&gt; question2Box.Text = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 105: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 106: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 107: &lt;/span&gt; &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 108: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MvpMain_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
EventArgs e)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 109: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 110: &lt;/span&gt; _presenter = SurveyPresenter.Instance(&lt;span class="kwrd"&gt;this&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 111: &lt;/span&gt; _presenter.OnLoad();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 112: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 113: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; userList_SelectedIndexChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
EventArgs e)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 114: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 115: &lt;/span&gt; _presenter.SelectedIndexChanged(userList.SelectedIndex);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 116: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 117: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Method 2
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ISurveyView&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
Users { get; set; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Question1 { get;
set; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Question2
{ get; set; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; SelectionChangedDelegate
SelectionChanged;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; OnLoadDelegate
OnLoad;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SelectionChangedDelegate(&lt;span class="kwrd"&gt;int&lt;/span&gt; index);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnLoadDelegate();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SurveyPresenter&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; ISurveyView _view;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; SurveyPresenter(ISurveyView
view)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt;_view = view;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt;_view.OnLoad += &lt;span class="kwrd"&gt;new&lt;/span&gt; OnLoadDelegate(OnLoad);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt;_view.SelectionChanged += &lt;span class="kwrd"&gt;new&lt;/span&gt; i&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt;SelectionChangedDelegate(SelectedIndexChanged);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 22: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnLoad()&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 23: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 24: &lt;/span&gt;&lt;span class="rem"&gt;//this is where you would go
to the&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 25: &lt;/span&gt;&lt;span class="rem"&gt;//model for data,
but we’ll cheat&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 26: &lt;/span&gt;List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; users
= &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;[]
i&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 27: &lt;/span&gt;{ &lt;span class="str"&gt;"Fred"&lt;/span&gt;, &lt;span class="str"&gt;"Bob"&lt;/span&gt;, &lt;span class="str"&gt;"Patty"&lt;/span&gt; });&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 28: &lt;/span&gt;_view.Users = users;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 29: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 30: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SelectedIndexChanged(&lt;span class="kwrd"&gt;int&lt;/span&gt; index)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 31: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 32: &lt;/span&gt; &lt;span class="rem"&gt;//go to the model and get answers
for questions&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 33: &lt;/span&gt; &lt;span class="rem"&gt;//we’ll make it
up&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 34: &lt;/span&gt; &lt;span class="rem"&gt;//This is also where the answers
to the previous&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 35: &lt;/span&gt; &lt;span class="rem"&gt;//questions would
be saved back to the model.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 36: &lt;/span&gt; _view.Question1 = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 37: &lt;/span&gt; _view.Question2 = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0}
is cool!"&lt;/span&gt;, _view.Users[index]);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 38: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 39: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 40: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MvpMain
: Form, ISurveyView&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 41: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 42: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; MvpMain()&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 43: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 44: &lt;/span&gt; InitializeComponent();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 45: &lt;/span&gt; _presenter = &lt;span class="kwrd"&gt;new&lt;/span&gt; SurveyPresenter(&lt;span class="kwrd"&gt;this&lt;/span&gt;);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 46: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 47: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; SurveyPresenter
_presenter;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 48: &lt;/span&gt; &lt;span class="preproc"&gt;#region&lt;/span&gt; ISurveyView
Members&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 49: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
Users&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 50: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 51: &lt;/span&gt; get&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 52: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 53: &lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
users = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 54: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;object&lt;/span&gt; item &lt;span class="kwrd"&gt;in&lt;/span&gt; userList.Items)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 55: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 56: &lt;/span&gt; users.Add((&lt;span class="kwrd"&gt;string&lt;/span&gt;)item);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 57: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 58: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; users;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 59: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 60: &lt;/span&gt; set&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 61: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 62: &lt;/span&gt; userList.Items.Clear();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 63: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; user &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 64: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 65: &lt;/span&gt; userList.Items.Add(user);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 66: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 67: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 68: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 69: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Question1&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 70: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 71: &lt;/span&gt; get&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 72: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 73: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (yesButton.Checked)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 74: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 75: &lt;/span&gt; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 76: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 77: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 78: &lt;/span&gt; set&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 79: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 80: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 81: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 82: &lt;/span&gt; yesButton.Checked = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 83: &lt;/span&gt; noButton.Checked = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 84: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 85: &lt;/span&gt; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 86: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 87: &lt;/span&gt; yesButton.Checked = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 88: &lt;/span&gt; noButton.Checked = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 89: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 90: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 91: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 92: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Question2&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 93: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 94: &lt;/span&gt; get&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 95: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 96: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; question2Box.Text;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 97: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 98: &lt;/span&gt; set&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 99: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 100: &lt;/span&gt; question2Box.Text = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 101: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 102: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 103: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; OnLoadDelegate
OnLoad;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 104: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; SelectionChangedDelegate
SelectionChanged;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 105: &lt;/span&gt; &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 106: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MvpMain_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
EventArgs e)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 107: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 108: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (OnLoad != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 109: &lt;/span&gt; OnLoad();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 110: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 111: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; userList_SelectedIndexChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
EventArgs e)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 112: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 113: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (SelectionChanged
!= &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 114: &lt;/span&gt; SelectionChanged(userList.SelectedIndex);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 115: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 116: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=7ff0a174-37a0-4056-b0cf-f9acc5595c54" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,7ff0a174-37a0-4056-b0cf-f9acc5595c54.aspx</comments>
      <category>Design;DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=cc872bf2-7aa4-4701-a91f-751402407f6e</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,cc872bf2-7aa4-4701-a91f-751402407f6e.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,cc872bf2-7aa4-4701-a91f-751402407f6e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=cc872bf2-7aa4-4701-a91f-751402407f6e</wfw:commentRss>
      <title>.Net Review (part 3)</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,cc872bf2-7aa4-4701-a91f-751402407f6e.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,cc872bf2-7aa4-4701-a91f-751402407f6e.aspx</link>
      <pubDate>Fri, 19 Mar 2010 20:12:42 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/dd419663.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;h5&gt;M-V-VM pattern
&lt;/h5&gt;
&lt;p&gt;
The PM pattern is similar to MVP in that it separates a view from its behavior and
state. The interesting part of the PM pattern is that an abstraction of a view is
created, called the Presentation Model. A view, then, becomes merely a rendering of
a Presentation Model. In Fowler's explanation, he shows that the Presentation Model
frequently updates its View, so that the two stay in sync with each other. That synchronization
logic exists as code in the Presentation Model classes.
&lt;/p&gt;
&lt;p&gt;
Unlike the Presenter in MVP, &lt;strong&gt;a ViewModel does not need a reference to a view&lt;/strong&gt;.
The view binds to properties on a ViewModel, which, in turn, exposes data contained
in model objects and other state specific to the view. The bindings between view and
ViewModel are simple to construct because a ViewModel object is set as the DataContext
of a view. If property values in the ViewModel change, those new values automatically
propagate to the view via data binding. When the user clicks a button in the View,
a command on the ViewModel executes to perform the requested action. The ViewModel,
never the View, performs all modifications made to the model data.
&lt;/p&gt;
&lt;p&gt;
The single most important aspect of WPF that makes MVVM a great pattern to use is
the &lt;strong&gt;data binding infrastructure&lt;/strong&gt;. By binding properties of a view
to a ViewModel, you get loose coupling between the two and entirely remove the need
for writing code in a ViewModel that directly updates a view. The data binding system
also supports input validation, which provides a standardized way of transmitting
validation errors to a view. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Two other features of WPF that make this pattern so usable are &lt;strong&gt;data templates
and the resource system&lt;/strong&gt;. Data templates apply Views to ViewModel objects
shown in the user interface. You can declare templates in XAML and let the resource
system automatically locate and apply those templates for you at run time. You can
learn more about binding and data templates in my July 2008 article, "&lt;a href="http://msdn.microsoft.com/magazine/cc700358"&gt;Data
and WPF: Customize Data Display with Data Binding and WPF&lt;/a&gt;." 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
If it were not for the support for &lt;strong&gt;commands in WPF&lt;/strong&gt;, the MVVM pattern
would be much less powerful. In this article, I will show you how a ViewModel can
expose commands to a View, thus allowing the view to consume its functionality. If
you aren't familiar with commanding, I recommend that you read Brian Noyes's comprehensive
article, "&lt;a href="http://msdn.microsoft.com/magazine/cc785480"&gt;Advanced WPF: Understanding
Routed Events and Commands in WPF&lt;/a&gt;," from the September 2008 issue. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
In addition to the WPF (and Silverlight 2) features that make MVVM a natural way to
structure an application, the pattern is also popular because ViewModel classes are
easy to unit test. When an application's interaction logic lives in a set of ViewModel
classes, you can &lt;strong&gt;easily write code that tests it&lt;/strong&gt;. In a sense, Views
and unit tests are just two different types of ViewModel consumers. Having a suite
of tests for an application's ViewModels provides free and fast regression testing,
which helps reduce the cost of maintaining an application over time. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
In addition to promoting the creation of automated regression tests, the testability
of ViewModel classes can assist in properly designing user interfaces that are easy
to skin. When you are designing an application, you can often decide whether something
should be in the view or the ViewModel by imagining that you want to write a unit
test to consume the ViewModel. If you can write unit tests for the ViewModel without
creating any UI objects, you can also completely skin the ViewModel because it has
no dependencies on specific visual elements. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Lastly, for developers who work with visual designers, using MVVM makes it much easier
to create &lt;strong&gt;a smooth designer/developer workflow&lt;/strong&gt;. Since a view is just
an arbitrary consumer of a ViewModel, it is easy to just rip one view out and drop
in a new view to render a ViewModel. This simple step allows for rapid prototyping
and evaluation of user interfaces made by the designers. 
&lt;p&gt;
The development team can focus on creating robust ViewModel classes, and the design
team can focus on making user-friendly Views. Connecting the output of both teams
can involve little more than ensuring that the correct bindings exist in a view's
XAML file. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Relaying Command Logic&lt;/strong&gt; 
&lt;p&gt;
Every view in the app has an empty codebehind file, except for the standard boilerplate
code that calls InitializeComponent in the class's constructor. In fact, you could
remove the views' codebehind files from the project and the application would still
compile and run correctly. Despite the lack of event handling methods in the views,
when the user clicks on buttons, the application reacts and satisfies the user's requests.
This works because of bindings that were established on the Command property of Hyperlink,
Button, and MenuItem controls displayed in the UI. Those bindings ensure that when
the user clicks on the controls, ICommand objects exposed by the ViewModel execute.
You can think of the command object as an adapter that makes it easy to consume a
ViewModel's functionality from a view declared in XAML. 
&lt;p&gt;
When a ViewModel exposes an instance property of type I&amp;shy;Command, the command object
typically uses that ViewModel object to get its job done. One possible implementation
pattern is to create a private nested class within the ViewModel class, so that the
command has access to private members of its containing ViewModel and does not pollute
the namespace. That nested class implements the ICommand interface, and a reference
to the containing ViewModel object is injected into its constructor. However, creating
a nested class that implements ICommand for each command exposed by a ViewModel can
bloat the size of the ViewModel class. More code means a greater potential for bugs. 
&lt;p&gt;
In the demo application, the RelayCommand class solves this problem. &lt;strong&gt;RelayCommand
allows you to inject the command's logic via delegates passed into its constructor.&lt;/strong&gt; This
approach allows for terse, concise command implementation in ViewModel classes. RelayCommand
is a simplified variation of the DelegateCommand found in the &lt;a href="http://msdn.microsoft.com/library/cc707890"&gt;Microsoft
Composite Application Library&lt;/a&gt;. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Data-binding in WPF&lt;/strong&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a title="http://www.nbdtech.com/Free/WpfBinding.pdf" href="http://www.nbdtech.com/Free/WpfBinding.pdf"&gt;http://www.nbdtech.com/Free/WpfBinding.pdf&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_thumb_1.png" width="586" height="384"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_thumb.png" width="618" height="609"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_thumb_2.png" width="508" height="191"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_thumb_3.png" width="576" height="271"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_thumb_4.png" width="584" height="279"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_thumb_5.png" width="597" height="441"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_14.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/f6ad9ce20ad1.NetReviewpart3_E44B/image_thumb_6.png" width="532" height="259"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=cc872bf2-7aa4-4701-a91f-751402407f6e" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,cc872bf2-7aa4-4701-a91f-751402407f6e.aspx</comments>
      <category>DotNet;DotNet / WPF</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=319ac4e6-36c2-4cf0-84da-e3df77335d89</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,319ac4e6-36c2-4cf0-84da-e3df77335d89.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,319ac4e6-36c2-4cf0-84da-e3df77335d89.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=319ac4e6-36c2-4cf0-84da-e3df77335d89</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://thedatafarm.com/LearnEntityFramework/resources/" href="http://thedatafarm.com/LearnEntityFramework/resources/">http://thedatafarm.com/LearnEntityFramework/resources/</a>
          <br />
          <a title="http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx" href="http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx">http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=319ac4e6-36c2-4cf0-84da-e3df77335d89" />
      </body>
      <title>EDM Resources</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,319ac4e6-36c2-4cf0-84da-e3df77335d89.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,319ac4e6-36c2-4cf0-84da-e3df77335d89.aspx</link>
      <pubDate>Sun, 14 Mar 2010 14:22:46 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://thedatafarm.com/LearnEntityFramework/resources/" href="http://thedatafarm.com/LearnEntityFramework/resources/"&gt;http://thedatafarm.com/LearnEntityFramework/resources/&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx" href="http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx"&gt;http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=319ac4e6-36c2-4cf0-84da-e3df77335d89" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,319ac4e6-36c2-4cf0-84da-e3df77335d89.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=0fd019c4-6afd-452e-a516-ef2314156e62</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,0fd019c4-6afd-452e-a516-ef2314156e62.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,0fd019c4-6afd-452e-a516-ef2314156e62.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0fd019c4-6afd-452e-a516-ef2314156e62</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <br />
It is possible to set a minumum length e.g.<br />
string.format("{0,10:s}",12345"); will return a string 10 chars long with right alignment 
</p>
        <p>
string.format("{0,10:s}",12345"); will return a string 10 chars long with left alignment
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=0fd019c4-6afd-452e-a516-ef2314156e62" />
      </body>
      <title>String format tricks</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,0fd019c4-6afd-452e-a516-ef2314156e62.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,0fd019c4-6afd-452e-a516-ef2314156e62.aspx</link>
      <pubDate>Fri, 12 Mar 2010 22:02:29 GMT</pubDate>
      <description>&lt;p&gt;
&lt;br&gt;
It is possible to set a minumum length e.g.&lt;br&gt;
string.format("{0,10:s}",12345"); will return a string 10 chars long with right alignment 
&lt;p&gt;
string.format("{0,10:s}",12345"); will return a string 10 chars long with left alignment
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=0fd019c4-6afd-452e-a516-ef2314156e62" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,0fd019c4-6afd-452e-a516-ef2314156e62.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=d10d9b17-79fb-435c-bcdd-fcc3490c08be</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,d10d9b17-79fb-435c-bcdd-fcc3490c08be.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,d10d9b17-79fb-435c-bcdd-fcc3490c08be.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d10d9b17-79fb-435c-bcdd-fcc3490c08be</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a name="pose a">
          </a>Well-designed databases can pose a problem for developers.<a name="I_indexterm2_d1e1560"></a></p>
        <p>
          <a name="a database">
          </a>In the data world, a database is designed for maintainability,
security, efficiency, and scalability. Its data is organized in a way that satisfies
the demands of a good database administrator, yet provides challenges for the developer
who needs to access that data. 
</p>
        <p>
  
</p>
        <p>
The EDM follows this concept, but in the Entity Framework, it moves the modeling into
XML files that different programming models can use. The primary XML file contains
the <strong>conceptual model</strong>, which is the actual EDM. A second XML file
contains a <strong>representation of the database</strong> and a third, the <strong>mapping</strong> between
the first two. At design time, all three files are bundled into a single EDMX file.
The build process splits the EDMX out into the three metadata files that are used
at runtime. The Entity Framework then provides a framework that allows developers
to write .NET applications based on this model. 
</p>
        <p>
  
</p>
        <p>
          <a name="As long">
          </a>As long as the EDM provides the conceptual schema, a representation
of the database, a mapping file, and access to an Entity Framework-aware ADO.NET provider
for the target database, the Entity Framework doesn't care what database is being
targeted. It provides a common means of interacting with the database, common query
syntax, and a common method for sending changes back to the database.<a name="I_indexterm2_d1e1588"></a></p>
        <p>
          <a name="Framework provides">
          </a>Although the Entity Framework provides a very rich
set of features for developers, its most important capabilities are the following: 
</p>
        <ul>
          <li>
            <p>
              <a name="classes from">
              </a>It automatically generates classes from the model and updates
those classes dynamically anytime the model changes.
</p>
          </li>
          <li>
            <p>
              <a name="care of">
              </a>It takes care of all of the database connectivity so that developers
are not burdened by having to write lots of code for interacting with the database.
</p>
          </li>
          <li>
            <p>
              <a name="query syntax">
              </a>It provides common query syntax for querying the model,
not the database, and then translates these queries into queries that the database
can understand.
</p>
          </li>
          <li>
            <p>
              <a name="as they">
              </a>It provides a mechanism for tracking changes to the model's
objects as they are being used in applications, and handles the updates to the database.
</p>
          </li>
        </ul>
        <p>
          <a name="changes to">
          </a>In addition, because the model's classes are dynamically
generated, minor changes to the model need not have a major impact on your application.
Furthermore, modifying the model is much simpler than modifying your objects and the
data access code on which they rely. 
</p>
        <p>
  
</p>
        <p>
Navigation properties are pointers to related entities.<br />
An Entity Set<a name="for a"></a> is a container for a collection of entities of a
single type.<br /></p>
        <p>
          <a name="a&#xD;&#xA;        step">
          </a>Cleaning up the entity, property, and association names
is a step that you should consider performing immediately after you create a new model
with the ADO.NET Entity Data Model Wizard. In this way, as you begin to code against
the model, the names of the objects will be logical. Additionally, if you change these
names after you have begun to code, you will have to modify your code to reflect the
changes. 
</p>
        <p>
  
</p>
        <p>
The EDMX file is composed of two main sections: the runtime information and the Designer
information. The runtime section comprises three additional sections: one each for
storage models, conceptual models, and mappings. The Designer section specifies where
the various model elements should be placed visually in the Designer. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb.png" width="503" height="305" />
          </a>
        </p>
        <p>
  
</p>
        <p>
Why use the storage layer to represent the data store when you have the actual data
store to work with? There are a number of reasons to use this piece of the model.
The most important reason is that this provides loose coupling to the database; not
every object in the database needs to be in the mode 
</p>
        <p>
  
</p>
        <p>
Although the entire model is contained in a single file at design time, when the project
is compiled it will create three separate files—one for each of these sections. The
conceptual layer is saved to a file with a <i>.csdl</i><a name="storage layer"></a> extension,
which stands for Conceptual Schema Definition Language. The storage layer is saved
to a file with an <i>.ssdl</i><a name="Schema Definition"></a> extension (which stands
for Store Schema Definition Language) and the mapping layer is saved to a file with
an <i>.msl</i><a name="which is"></a> extension (which stands for Mapping Specification
Language). These files are used at runtime, which is why they are contained in a section
called <tt>edmx:Runtime</tt><a name="in the"></a> in the model. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_1.png" width="603" height="296" />
          </a>
        </p>
        <p>
        </p>
        <p>
          <a name="container for">
          </a>Although it makes sense to have a container for an entity
because you could have many contact entities to work with, how would there be a collection
of associations? When you are working with entity objects, the associations between
the entities are also objects. If you have a single contact with multiple addresses
in memory, there would be one <tt>FK_Address_Contact</tt> association object for each
relationship. <a href="#two_association_objects_defining_relatio">Figure 2-14</a><a name="that are"></a> shows
two association objects that are used to define relationships between a single contact
and two addresses. 
</p>
        <p>
  
</p>
        <p>
&lt;NavigationProperty Name="Contact" 
</p>
        <p>
                     
Relationship="ProgrammingEFDB1Model.FK_Address_Contact" 
</p>
        <p>
                      
FromRole="Address" ToRole="Contact" /&gt; 
</p>
        <p>
  
</p>
        <p>
The collection that is exposed in the <tt>Addresses</tt><a name="not a"></a> navigation
property is not a collection from the <tt>System.Collections</tt> namespace, but rather
an <tt>EntityCollection</tt>. The <tt>EntityCollection</tt><a name="unique class"></a> is
a completely unique class in the Entity Framework. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_3.png" width="673" height="645" />
          </a>
        </p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_2.png" width="521" height="392" />
          </a>
        </p>
        <p>
        </p>
        <p>
The <tt>ReferentialConstraint</tt><a name="the&#xD;&#xA;        relationship"></a> element
serves a number of purposes. It specifies the direction of the relationship using
the Principal and Dependent role elements. In the example, <tt>Address</tt><a name="is dependent"></a> is
dependent upon <tt>Contact</tt><a name="to&#xD;&#xA;        defining"></a>. This also translates
to defining the primary key/foreign key relationship, and we finally see the foreign
key in the <tt>Address</tt><a name="the"></a> table identified: it is the <tt>ContactID</tt><a name="another piece"></a>.
This is another piece of the puzzle of how the association and the navigation property
work in the conceptual model. The <tt>ContactID</tt><a name="in the"></a> property
doesn't exist anywhere in the CSDL, but it is specified here in the SSDL. The MSL
will show us how they are linked.
</p>
        <p>
The last purpose of the <tt>ReferentialConstraint</tt> element is to stipulate that
a row in the <tt>Address</tt><a name="the"></a> table cannot exist without a reference
to a row in the <tt>People</tt><a name="of the"></a> table.
</p>
        <p>
If you check back at the CSDL's association in <a href="csdl_the_conceptual_schema.html#the_association_between_contact_and_addr">Example
2-2</a><a name="that this"></a>, you will see that this <tt>ReferentialConstraint</tt><a name="that constraint"></a> doesn't
exist. The CSDL enforces that constraint in a different way. The multiplicity for
the <tt>Person</tt><a name="in that"></a> entity type in that relationship is "1",
not "0..1".
</p>
        <p>
Designer's Mapping Details window
</p>
        <p>
          <a name="the">
          </a>Open the model in the XML Editor again and expand the <tt>&lt;edmx:Mappings&gt;</tt><a name="in how"></a> section;
you'll see that there is one big difference in how the mapping is described under
the covers. The mapping, as shown in <a href="#the_xml_view_of_the_contact_entity_mappi">Example
2-4</a><a name="the"></a>, is being made from the <tt>EntitySet</tt><a name="you may"></a>,
not the actual entity. When you add inherited types into the mix, you may also be
mapping <tt>Customer</tt><a name="s who"></a>s who are a type of <tt>Contact</tt><a name="the"></a>.
When you map the <tt>EntitySet</tt><a name="of the"></a> you cover all of the entity
types in an inheritance hierarchy. Therefore, the mapping needs to be done to the <tt>EntitySet</tt><a name="specific entity"></a>,
not a specific entity. 
</p>
        <p>
 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_10.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_4.png" width="545" height="265" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_12.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_5.png" width="557" height="308" />
          </a>
        </p>
        <p>
          <a name="The Entity">
          </a>The Entity Framework automatically creates a set of classes
from the model. These classes are what you will work with when you query the model,
and objects will be returned that are based on these classes.<a name="I_indexterm2_d1e3773"></a><a name="I_indexterm2_d1e3778"></a><a name="I_indexterm2_d1e3783"></a></p>
        <p>
          <a name="change is">
          </a>Each time a change is made to the model and the model is then
saved, the Entity Framework's code generator kicks in and the classes are re-created. 
</p>
        <p>
  
</p>
        <p>
          <tt>
            <strong>
              <font color="#0000ff">IQueryable</font>
            </strong>
          </tt>
          <a name="LINQ query">
          </a> is
a LINQ query type. At design time, the compiler recognizes the LINQ query and does
its best to tell you its return type. The compiler doesn't realize that because it
is a LINQ to Entities<a name="it will"></a> query, it will be processed by the Entity
Framework and will result in an <tt>ObjectQuery</tt>. <font color="#0000ff"><tt>ObjectQuery</tt> implements <tt>IQueryable</tt></font><a name="are very"></a>,
so the two are very closely related. 
</p>
        <p>
        </p>
        <p>
          <tt>IQueryable</tt>
          <a name="the query">
          </a> contains metadata about the query, such
as the query expression and the provider being used. <tt>ObjectQuery</tt> is an <tt>IQueryable</tt><a name="query details"></a> with
additional query details that are specific to Entity Framework queries.
</p>
        <p>
The results are described as an "enumerable type," based on the class <tt>IEnumerable</tt>,
which is similar to a <tt>Collection</tt>. An <tt>IEnumerable</tt><a name="the collection"></a> allows
you to enumerate or iterate through each item in the collection as you did in the
preceding code sample (i.e., in <tt><a name="For Each"></a>For Each</tt>/<tt>foreach</tt>).
A <tt>Collection</tt> is an enhanced <tt>IEnumerable</tt>. Whereas an <tt>IEnumerable</tt><a name="familiar"></a> is
read-only, the more familiar <tt>Collection</tt><a name="to perform"></a> class allows
you to perform additional actions, such as adding or removing items from the group.
</p>
        <p>
          <strong>EntityClient</strong>: The Lowest-Level Method for Returning Streamed Data
Through EDM Queries
</p>
        <p>
//add new entities
</p>
        <div class="csharpcode">
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_18.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_8.png" width="534" height="161" />
          </a>
        </div>
        <p>
//insert new parents and children
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_16.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_7.png" width="522" height="242" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_14.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_6.png" width="527" height="377" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_20.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_9.png" width="522" height="418" />
          </a>
        </p>
        <p>
          <a name="You can">
          </a>You can divide the core functionality of Object Services into
seven areas:<a name="I_indexterm9_d1e16964"></a></p>
        <ul>
          <li>
            <p>
Query processing
</p>
          </li>
          <li>
            <p>
Object materialization
</p>
          </li>
          <li>
            <p>
Object management
</p>
          </li>
          <li>
            <p>
Object relationship management
</p>
          </li>
          <li>
            <p>
Object state management
</p>
          </li>
          <li>
            <p>
              <a name="command processing">
              </a>Database Manipulation Language (DML) command processing
</p>
          </li>
          <li>
            <p>
Additional features
</p>
          </li>
        </ul>
        <p>
          <a name="high level">
          </a>At a high level, query processing in the Entity Framework
involves translating the LINQ or Entity SQL queries into queries that the data store
can process. At a lower level, it first parses your query into a command tree of LINQ
or Entity SQL query operators and functions, combined with the necessary entities
and properties of your model. The command tree is a format that the various providers
that have been designed to work with the Entity Framework will be expecting. Next,
the provider API (Oracle, SQL Server, MySQL, etc.) transforms this tree into a new
expression tree composed of the provider's operators and functions and the database's
tables and columns. This tree is finally passed to the database.<a name="I_indexterm9_d1e17014"></a><a name="I_indexterm9_d1e17017"></a></p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
          <a name="LINQ starts">
          </a>LINQ starts its journey in the LINQ APIs and is then passed
to the Object Services API. When you create a LINQ to Entities query, you are using
syntax that is built into Visual Basic and C# that has enhancements that the Entity
Framework has added. LINQ converts this query into a LINQ expression tree, which deconstructs
the query into its common operators and functions. The LINQ expression tree is then
passed to Object Services, which converts the expression tree to a command tree. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_22.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_10.png" width="508" height="363" />
          </a>
        </p>
        <p>
 
</p>
        <p>
          <a name="I_indexterm9_d1e17056">
          </a>
          <strong>
            <font color="#0000ff">Customizing Entity
Data Models</font>
          </strong>
        </p>
        <p>
In object-oriented programming, when one object is a type of another object, you can
use inheritance to share properties so that the properties of a base type (e.g., <tt>Contact</tt>)
are exposed directly in a derived type (e.g., <tt>Customer</tt><a name="allow"></a>).
The EDM supports inheritance as well. The inheritance mapping used to allow <tt>Customer</tt> to
derive from <tt>Contact</tt> and absorb <tt>Contact</tt>'s properties is called <strong>Table
per Type inheritance</strong><a name="to simplify"></a>. Let's investigate this one
first, and modify the model to simplify working with customers.<a name="I_indexterm9_d1e17066"></a></p>
        <p>
          <strong>Entity splitting</strong>, also referred to as vertical splitting<a name="map a"></a>,
allows you to map a single entity to more than one table. You can use entity splitting
when tables share a common key; for example, if a contact's personal and business
information is stored in separate tables. You can use entity splitting as long as
the primary keys in the two database tables match.<br />
(Entity splitting can solve this problem very easily, by mapping both the <tt>Customer</tt> table
and the <tt>ContactPersonalInfo</tt> table to the <tt>Customer</tt> entity.)
</p>
        <p>
          <strong>Conditional mapping</strong> places a permanent filter on an entity by defining
that an entity will be mapped to data in the database under only certain conditions.
</p>
        <p>
          <a name="Another type">
          </a>Another type of inheritance that the EDM supports is <strong>Table
per Hierarchy (TPH).</strong> TPH inheritance depends on conditional mapping. Rather
than including only records that match the condition, the condition is used to define
records as different types. 
</p>
        <p>
  
</p>
        <p>
          <strong>Creating Complex Types to Encapsulate Sets of Properties</strong>
        </p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
          <tt>
            <strong>
              <font size="2">QueryView</font>
            </strong>
          </tt>
          <a name="is a">
          </a> is a
mapping that allows you to override the default mapping for an entity set and return
read-only data. <tt>QueryView</tt><a name="need to"></a> is something you need to
enter manually in the XML, and it belongs in the mapping layer. <a name="ch12_QueryView"></a><a name="ch12_EDMcustomQV"></a><a name="ch12_mappingsQV"></a></p>
        <p>
A <tt>QueryView</tt><a name="that is"></a> is a query that is expressed using Entity
SQL syntax. However, rather than creating the Entity SQL expression against the conceptual
layer of the model, the target of the expression is the store (SSDL) layer. In other
words, when you construct the Entity SQL for a <tt>QueryView</tt><a name="is written"></a>,
the query is written against the elements of the SSDL.<br /></p>
        <p>
Although <tt>QueryView</tt> returns read-only entities, if you want to use <tt>QueryView</tt><a name="to be"></a> for
some of its other benefits, you can force the entity to be updatable. Entities that
are mapped with <tt>QueryView</tt> are still change-tracked by the <tt>ObjectContext</tt><a name="automatically generate"></a>.
However, the Entity Framework is not able to automatically generate <tt>Insert</tt>, <tt>Update</tt>,
and <tt>Delete</tt><a name="can always"></a> commands for these entities. Instead,
you can always create function mappings, as you did for the <tt>Payment</tt> entity.
Then the entity that came from a <tt>QueryView</tt> will be affected by the call to <tt>SaveChanges</tt>.<br /></p>
        <p>
In addition to returning read-only entities, another benefit of <tt>QueryView</tt><a name="you saw"></a> is
that you can overcome the limitations of conditional mapping. As you saw earlier,
conditional mapping lets you filter using <tt>=</tt>, <tt><a name="Is Null"></a>Is
Null</tt>, and <tt>Is Not Null</tt>. 
<br />
Using a <tt>QueryView</tt><a name="with a"></a><strong>you can filter with a much
wider variety of operators</strong>, including <tt>&gt;</tt> and <tt>&lt;</tt>. However,
because <tt>QueryView</tt><a name="need the"></a> returns read-only data, if you need
the entity that results to be updatable, you can still achieve this by mapping stored
procedures to the entity that results.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=d10d9b17-79fb-435c-bcdd-fcc3490c08be" />
      </body>
      <title>Excerps from Programming Entity Framework</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,d10d9b17-79fb-435c-bcdd-fcc3490c08be.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,d10d9b17-79fb-435c-bcdd-fcc3490c08be.aspx</link>
      <pubDate>Wed, 10 Mar 2010 20:25:05 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a name="pose a"&gt;&lt;/a&gt;Well-designed databases can pose a problem for developers.&lt;a name="I_indexterm2_d1e1560"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;a name="a database"&gt;&lt;/a&gt;In the data world, a database is designed for maintainability,
security, efficiency, and scalability. Its data is organized in a way that satisfies
the demands of a good database administrator, yet provides challenges for the developer
who needs to access that data. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The EDM follows this concept, but in the Entity Framework, it moves the modeling into
XML files that different programming models can use. The primary XML file contains
the &lt;strong&gt;conceptual model&lt;/strong&gt;, which is the actual EDM. A second XML file
contains a &lt;strong&gt;representation of the database&lt;/strong&gt; and a third, the &lt;strong&gt;mapping&lt;/strong&gt; between
the first two. At design time, all three files are bundled into a single EDMX file.
The build process splits the EDMX out into the three metadata files that are used
at runtime. The Entity Framework then provides a framework that allows developers
to write .NET applications based on this model. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a name="As long"&gt;&lt;/a&gt;As long as the EDM provides the conceptual schema, a representation
of the database, a mapping file, and access to an Entity Framework-aware ADO.NET provider
for the target database, the Entity Framework doesn't care what database is being
targeted. It provides a common means of interacting with the database, common query
syntax, and a common method for sending changes back to the database.&lt;a name="I_indexterm2_d1e1588"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;a name="Framework provides"&gt;&lt;/a&gt;Although the Entity Framework provides a very rich
set of features for developers, its most important capabilities are the following: 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="classes from"&gt;&lt;/a&gt;It automatically generates classes from the model and updates
those classes dynamically anytime the model changes.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="care of"&gt;&lt;/a&gt;It takes care of all of the database connectivity so that developers
are not burdened by having to write lots of code for interacting with the database.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="query syntax"&gt;&lt;/a&gt;It provides common query syntax for querying the model,
not the database, and then translates these queries into queries that the database
can understand.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="as they"&gt;&lt;/a&gt;It provides a mechanism for tracking changes to the model's
objects as they are being used in applications, and handles the updates to the database.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a name="changes to"&gt;&lt;/a&gt;In addition, because the model's classes are dynamically
generated, minor changes to the model need not have a major impact on your application.
Furthermore, modifying the model is much simpler than modifying your objects and the
data access code on which they rely. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Navigation properties are pointers to related entities.&lt;br&gt;
An Entity Set&lt;a name="for a"&gt;&lt;/a&gt; is a container for a collection of entities of a
single type.&lt;br&gt;
&lt;p&gt;
&lt;a name="a
        step"&gt;&lt;/a&gt;Cleaning up the entity, property, and association names
is a step that you should consider performing immediately after you create a new model
with the ADO.NET Entity Data Model Wizard. In this way, as you begin to code against
the model, the names of the objects will be logical. Additionally, if you change these
names after you have begun to code, you will have to modify your code to reflect the
changes. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The EDMX file is composed of two main sections: the runtime information and the Designer
information. The runtime section comprises three additional sections: one each for
storage models, conceptual models, and mappings. The Designer section specifies where
the various model elements should be placed visually in the Designer. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb.png" width="503" height="305"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Why use the storage layer to represent the data store when you have the actual data
store to work with? There are a number of reasons to use this piece of the model.
The most important reason is that this provides loose coupling to the database; not
every object in the database needs to be in the mode 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Although the entire model is contained in a single file at design time, when the project
is compiled it will create three separate files—one for each of these sections. The
conceptual layer is saved to a file with a &lt;i&gt;.csdl&lt;/i&gt;&lt;a name="storage layer"&gt;&lt;/a&gt; extension,
which stands for Conceptual Schema Definition Language. The storage layer is saved
to a file with an &lt;i&gt;.ssdl&lt;/i&gt;&lt;a name="Schema Definition"&gt;&lt;/a&gt; extension (which stands
for Store Schema Definition Language) and the mapping layer is saved to a file with
an &lt;i&gt;.msl&lt;/i&gt;&lt;a name="which is"&gt;&lt;/a&gt; extension (which stands for Mapping Specification
Language). These files are used at runtime, which is why they are contained in a section
called &lt;tt&gt;edmx:Runtime&lt;/tt&gt;&lt;a name="in the"&gt;&lt;/a&gt; in the model. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_1.png" width="603" height="296"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a name="container for"&gt;&lt;/a&gt;Although it makes sense to have a container for an entity
because you could have many contact entities to work with, how would there be a collection
of associations? When you are working with entity objects, the associations between
the entities are also objects. If you have a single contact with multiple addresses
in memory, there would be one &lt;tt&gt;FK_Address_Contact&lt;/tt&gt; association object for each
relationship. &lt;a href="#two_association_objects_defining_relatio"&gt;Figure 2-14&lt;/a&gt;&lt;a name="that are"&gt;&lt;/a&gt; shows
two association objects that are used to define relationships between a single contact
and two addresses. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;lt;NavigationProperty Name="Contact" 
&lt;p&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
Relationship="ProgrammingEFDB1Model.FK_Address_Contact" 
&lt;p&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
FromRole="Address" ToRole="Contact" /&amp;gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The collection that is exposed in the &lt;tt&gt;Addresses&lt;/tt&gt;&lt;a name="not a"&gt;&lt;/a&gt; navigation
property is not a collection from the &lt;tt&gt;System.Collections&lt;/tt&gt; namespace, but rather
an &lt;tt&gt;EntityCollection&lt;/tt&gt;. The &lt;tt&gt;EntityCollection&lt;/tt&gt;&lt;a name="unique class"&gt;&lt;/a&gt; is
a completely unique class in the Entity Framework. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_3.png" width="673" height="645"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_2.png" width="521" height="392"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
The &lt;tt&gt;ReferentialConstraint&lt;/tt&gt;&lt;a name="the
        relationship"&gt;&lt;/a&gt; element
serves a number of purposes. It specifies the direction of the relationship using
the Principal and Dependent role elements. In the example, &lt;tt&gt;Address&lt;/tt&gt;&lt;a name="is dependent"&gt;&lt;/a&gt; is
dependent upon &lt;tt&gt;Contact&lt;/tt&gt;&lt;a name="to
        defining"&gt;&lt;/a&gt;. This also translates
to defining the primary key/foreign key relationship, and we finally see the foreign
key in the &lt;tt&gt;Address&lt;/tt&gt;&lt;a name="the"&gt;&lt;/a&gt; table identified: it is the &lt;tt&gt;ContactID&lt;/tt&gt;&lt;a name="another piece"&gt;&lt;/a&gt;.
This is another piece of the puzzle of how the association and the navigation property
work in the conceptual model. The &lt;tt&gt;ContactID&lt;/tt&gt;&lt;a name="in the"&gt;&lt;/a&gt; property
doesn't exist anywhere in the CSDL, but it is specified here in the SSDL. The MSL
will show us how they are linked.
&lt;/p&gt;
&lt;p&gt;
The last purpose of the &lt;tt&gt;ReferentialConstraint&lt;/tt&gt; element is to stipulate that
a row in the &lt;tt&gt;Address&lt;/tt&gt;&lt;a name="the"&gt;&lt;/a&gt; table cannot exist without a reference
to a row in the &lt;tt&gt;People&lt;/tt&gt;&lt;a name="of the"&gt;&lt;/a&gt; table.
&lt;/p&gt;
&lt;p&gt;
If you check back at the CSDL's association in &lt;a href="csdl_the_conceptual_schema.html#the_association_between_contact_and_addr"&gt;Example
2-2&lt;/a&gt;&lt;a name="that this"&gt;&lt;/a&gt;, you will see that this &lt;tt&gt;ReferentialConstraint&lt;/tt&gt;&lt;a name="that constraint"&gt;&lt;/a&gt; doesn't
exist. The CSDL enforces that constraint in a different way. The multiplicity for
the &lt;tt&gt;Person&lt;/tt&gt;&lt;a name="in that"&gt;&lt;/a&gt; entity type in that relationship is "1",
not "0..1".
&lt;/p&gt;
&lt;p&gt;
Designer's Mapping Details window
&lt;/p&gt;
&lt;p&gt;
&lt;a name="the"&gt;&lt;/a&gt;Open the model in the XML Editor again and expand the &lt;tt&gt;&amp;lt;edmx:Mappings&amp;gt;&lt;/tt&gt;&lt;a name="in how"&gt;&lt;/a&gt; section;
you'll see that there is one big difference in how the mapping is described under
the covers. The mapping, as shown in &lt;a href="#the_xml_view_of_the_contact_entity_mappi"&gt;Example
2-4&lt;/a&gt;&lt;a name="the"&gt;&lt;/a&gt;, is being made from the &lt;tt&gt;EntitySet&lt;/tt&gt;&lt;a name="you may"&gt;&lt;/a&gt;,
not the actual entity. When you add inherited types into the mix, you may also be
mapping &lt;tt&gt;Customer&lt;/tt&gt;&lt;a name="s who"&gt;&lt;/a&gt;s who are a type of &lt;tt&gt;Contact&lt;/tt&gt;&lt;a name="the"&gt;&lt;/a&gt;.
When you map the &lt;tt&gt;EntitySet&lt;/tt&gt;&lt;a name="of the"&gt;&lt;/a&gt; you cover all of the entity
types in an inheritance hierarchy. Therefore, the mapping needs to be done to the &lt;tt&gt;EntitySet&lt;/tt&gt;&lt;a name="specific entity"&gt;&lt;/a&gt;,
not a specific entity. 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_4.png" width="545" height="265"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_5.png" width="557" height="308"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a name="The Entity"&gt;&lt;/a&gt;The Entity Framework automatically creates a set of classes
from the model. These classes are what you will work with when you query the model,
and objects will be returned that are based on these classes.&lt;a name="I_indexterm2_d1e3773"&gt;&lt;/a&gt;&lt;a name="I_indexterm2_d1e3778"&gt;&lt;/a&gt;&lt;a name="I_indexterm2_d1e3783"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;a name="change is"&gt;&lt;/a&gt;Each time a change is made to the model and the model is then
saved, the Entity Framework's code generator kicks in and the classes are re-created. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;tt&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;IQueryable&lt;/font&gt;&lt;/strong&gt;&lt;/tt&gt;&lt;a name="LINQ query"&gt;&lt;/a&gt; is
a LINQ query type. At design time, the compiler recognizes the LINQ query and does
its best to tell you its return type. The compiler doesn't realize that because it
is a LINQ to Entities&lt;a name="it will"&gt;&lt;/a&gt; query, it will be processed by the Entity
Framework and will result in an &lt;tt&gt;ObjectQuery&lt;/tt&gt;. &lt;font color="#0000ff"&gt;&lt;tt&gt;ObjectQuery&lt;/tt&gt; implements &lt;tt&gt;IQueryable&lt;/tt&gt;&lt;/font&gt;&lt;a name="are very"&gt;&lt;/a&gt;,
so the two are very closely related. 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;tt&gt;IQueryable&lt;/tt&gt;&lt;a name="the query"&gt;&lt;/a&gt; contains metadata about the query, such
as the query expression and the provider being used. &lt;tt&gt;ObjectQuery&lt;/tt&gt; is an &lt;tt&gt;IQueryable&lt;/tt&gt;&lt;a name="query details"&gt;&lt;/a&gt; with
additional query details that are specific to Entity Framework queries.
&lt;/p&gt;
&lt;p&gt;
The results are described as an "enumerable type," based on the class &lt;tt&gt;IEnumerable&lt;/tt&gt;,
which is similar to a &lt;tt&gt;Collection&lt;/tt&gt;. An &lt;tt&gt;IEnumerable&lt;/tt&gt;&lt;a name="the collection"&gt;&lt;/a&gt; allows
you to enumerate or iterate through each item in the collection as you did in the
preceding code sample (i.e., in &lt;tt&gt;&lt;a name="For Each"&gt;&lt;/a&gt;For Each&lt;/tt&gt;/&lt;tt&gt;foreach&lt;/tt&gt;).
A &lt;tt&gt;Collection&lt;/tt&gt; is an enhanced &lt;tt&gt;IEnumerable&lt;/tt&gt;. Whereas an &lt;tt&gt;IEnumerable&lt;/tt&gt;&lt;a name="familiar"&gt;&lt;/a&gt; is
read-only, the more familiar &lt;tt&gt;Collection&lt;/tt&gt;&lt;a name="to perform"&gt;&lt;/a&gt; class allows
you to perform additional actions, such as adding or removing items from the group.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;EntityClient&lt;/strong&gt;: The Lowest-Level Method for Returning Streamed Data
Through EDM Queries
&lt;/p&gt;
&lt;p&gt;
//add new entities
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_18.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_8.png" width="534" height="161"&gt;&lt;/a&gt; 
&lt;/div&gt;
&lt;p&gt;
//insert new parents and children
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_16.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_7.png" width="522" height="242"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_14.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_6.png" width="527" height="377"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_20.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_9.png" width="522" height="418"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a name="You can"&gt;&lt;/a&gt;You can divide the core functionality of Object Services into
seven areas:&lt;a name="I_indexterm9_d1e16964"&gt;&lt;/a&gt; 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
Query processing
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
Object materialization
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
Object management
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
Object relationship management
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
Object state management
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a name="command processing"&gt;&lt;/a&gt;Database Manipulation Language (DML) command processing
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
Additional features
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a name="high level"&gt;&lt;/a&gt;At a high level, query processing in the Entity Framework
involves translating the LINQ or Entity SQL queries into queries that the data store
can process. At a lower level, it first parses your query into a command tree of LINQ
or Entity SQL query operators and functions, combined with the necessary entities
and properties of your model. The command tree is a format that the various providers
that have been designed to work with the Entity Framework will be expecting. Next,
the provider API (Oracle, SQL Server, MySQL, etc.) transforms this tree into a new
expression tree composed of the provider's operators and functions and the database's
tables and columns. This tree is finally passed to the database.&lt;a name="I_indexterm9_d1e17014"&gt;&lt;/a&gt;&lt;a name="I_indexterm9_d1e17017"&gt;&lt;/a&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a name="LINQ starts"&gt;&lt;/a&gt;LINQ starts its journey in the LINQ APIs and is then passed
to the Object Services API. When you create a LINQ to Entities query, you are using
syntax that is built into Visual Basic and C# that has enhancements that the Entity
Framework has added. LINQ converts this query into a LINQ expression tree, which deconstructs
the query into its common operators and functions. The LINQ expression tree is then
passed to Object Services, which converts the expression tree to a command tree. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_22.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_10.png" width="508" height="363"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a name="I_indexterm9_d1e17056"&gt;&lt;/a&gt;&lt;strong&gt;&lt;font color="#0000ff"&gt;Customizing Entity
Data Models&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In object-oriented programming, when one object is a type of another object, you can
use inheritance to share properties so that the properties of a base type (e.g., &lt;tt&gt;Contact&lt;/tt&gt;)
are exposed directly in a derived type (e.g., &lt;tt&gt;Customer&lt;/tt&gt;&lt;a name="allow"&gt;&lt;/a&gt;).
The EDM supports inheritance as well. The inheritance mapping used to allow &lt;tt&gt;Customer&lt;/tt&gt; to
derive from &lt;tt&gt;Contact&lt;/tt&gt; and absorb &lt;tt&gt;Contact&lt;/tt&gt;'s properties is called &lt;strong&gt;Table
per Type inheritance&lt;/strong&gt;&lt;a name="to simplify"&gt;&lt;/a&gt;. Let's investigate this one
first, and modify the model to simplify working with customers.&lt;a name="I_indexterm9_d1e17066"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Entity splitting&lt;/strong&gt;, also referred to as vertical splitting&lt;a name="map a"&gt;&lt;/a&gt;,
allows you to map a single entity to more than one table. You can use entity splitting
when tables share a common key; for example, if a contact's personal and business
information is stored in separate tables. You can use entity splitting as long as
the primary keys in the two database tables match.&lt;br&gt;
(Entity splitting can solve this problem very easily, by mapping both the &lt;tt&gt;Customer&lt;/tt&gt; table
and the &lt;tt&gt;ContactPersonalInfo&lt;/tt&gt; table to the &lt;tt&gt;Customer&lt;/tt&gt; entity.)
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Conditional mapping&lt;/strong&gt; places a permanent filter on an entity by defining
that an entity will be mapped to data in the database under only certain conditions.
&lt;/p&gt;
&lt;p&gt;
&lt;a name="Another type"&gt;&lt;/a&gt;Another type of inheritance that the EDM supports is &lt;strong&gt;Table
per Hierarchy (TPH).&lt;/strong&gt; TPH inheritance depends on conditional mapping. Rather
than including only records that match the condition, the condition is used to define
records as different types. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Creating Complex Types to Encapsulate Sets of Properties&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp; 
&lt;p&gt;
&lt;tt&gt;&lt;strong&gt;&lt;font size="2"&gt;QueryView&lt;/font&gt;&lt;/strong&gt;&lt;/tt&gt;&lt;a name="is a"&gt;&lt;/a&gt; is a
mapping that allows you to override the default mapping for an entity set and return
read-only data. &lt;tt&gt;QueryView&lt;/tt&gt;&lt;a name="need to"&gt;&lt;/a&gt; is something you need to
enter manually in the XML, and it belongs in the mapping layer. &lt;a name="ch12_QueryView"&gt;&lt;/a&gt;&lt;a name="ch12_EDMcustomQV"&gt;&lt;/a&gt;&lt;a name="ch12_mappingsQV"&gt;&lt;/a&gt; 
&lt;p&gt;
A &lt;tt&gt;QueryView&lt;/tt&gt;&lt;a name="that is"&gt;&lt;/a&gt; is a query that is expressed using Entity
SQL syntax. However, rather than creating the Entity SQL expression against the conceptual
layer of the model, the target of the expression is the store (SSDL) layer. In other
words, when you construct the Entity SQL for a &lt;tt&gt;QueryView&lt;/tt&gt;&lt;a name="is written"&gt;&lt;/a&gt;,
the query is written against the elements of the SSDL.&lt;br&gt;
&lt;p&gt;
Although &lt;tt&gt;QueryView&lt;/tt&gt; returns read-only entities, if you want to use &lt;tt&gt;QueryView&lt;/tt&gt;&lt;a name="to be"&gt;&lt;/a&gt; for
some of its other benefits, you can force the entity to be updatable. Entities that
are mapped with &lt;tt&gt;QueryView&lt;/tt&gt; are still change-tracked by the &lt;tt&gt;ObjectContext&lt;/tt&gt;&lt;a name="automatically generate"&gt;&lt;/a&gt;.
However, the Entity Framework is not able to automatically generate &lt;tt&gt;Insert&lt;/tt&gt;, &lt;tt&gt;Update&lt;/tt&gt;,
and &lt;tt&gt;Delete&lt;/tt&gt;&lt;a name="can always"&gt;&lt;/a&gt; commands for these entities. Instead,
you can always create function mappings, as you did for the &lt;tt&gt;Payment&lt;/tt&gt; entity.
Then the entity that came from a &lt;tt&gt;QueryView&lt;/tt&gt; will be affected by the call to &lt;tt&gt;SaveChanges&lt;/tt&gt;.&lt;br&gt;
&lt;p&gt;
In addition to returning read-only entities, another benefit of &lt;tt&gt;QueryView&lt;/tt&gt;&lt;a name="you saw"&gt;&lt;/a&gt; is
that you can overcome the limitations of conditional mapping. As you saw earlier,
conditional mapping lets you filter using &lt;tt&gt;=&lt;/tt&gt;, &lt;tt&gt;&lt;a name="Is Null"&gt;&lt;/a&gt;Is
Null&lt;/tt&gt;, and &lt;tt&gt;Is Not Null&lt;/tt&gt;. 
&lt;br&gt;
Using a &lt;tt&gt;QueryView&lt;/tt&gt;&lt;a name="with a"&gt;&lt;/a&gt; &lt;strong&gt;you can filter with a much
wider variety of operators&lt;/strong&gt;, including &lt;tt&gt;&amp;gt;&lt;/tt&gt; and &lt;tt&gt;&amp;lt;&lt;/tt&gt;. However,
because &lt;tt&gt;QueryView&lt;/tt&gt;&lt;a name="need the"&gt;&lt;/a&gt; returns read-only data, if you need
the entity that results to be updatable, you can still achieve this by mapping stored
procedures to the entity that results.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=d10d9b17-79fb-435c-bcdd-fcc3490c08be" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,d10d9b17-79fb-435c-bcdd-fcc3490c08be.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=2e9d170a-7f75-410a-ba30-9d85e800ad61</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,2e9d170a-7f75-410a-ba30-9d85e800ad61.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,2e9d170a-7f75-410a-ba30-9d85e800ad61.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=2e9d170a-7f75-410a-ba30-9d85e800ad61</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.codeproject.com/KB/webservices/Programming_WCF.aspx" href="http://www.codeproject.com/KB/webservices/Programming_WCF.aspx">http://www.codeproject.com/KB/webservices/Programming_WCF.aspx</a>
        </p>
        <p>
The WCF programming model unifies <a href="http://en.wikipedia.org/wiki/Web_Services">Web
Services</a>, <a href="http://en.wikipedia.org/wiki/.NET_Remoting">.NET Remoting</a>, <a href="http://en.wikipedia.org/wiki/Microsoft_Transaction_Server">Distributed
Transactions</a>, and <a href="http://en.wikipedia.org/wiki/Microsoft_Message_Queuing">Message
Queues</a> into a single <a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">Service-oriented
programming</a> model for <a href="http://en.wikipedia.org/wiki/Distributed_computing">distributed
computing</a>. WCF uses <a href="http://en.wikipedia.org/wiki/SOAP">SOAP</a> messages
for communication between two processes, thereby making WCF-based applications interoperable
with any other process that communicates via SOAP messages.
</p>
        <p>
A WCF Service is composed of three components parts viz, 
</p>
        <p>
1) <strong>Service Class -</strong> A WCF service class implements some service as
a set of methods. 
</p>
        <p>
2) <strong>Host Environment</strong> - A Host environment can be a Console application
or a Windows Service or a Windows Forms application or IIS as in case of the normal
asmx web service in .NET. 
</p>
        <p>
3) <strong>Endpoints</strong> - All communications with the WCF service will happen
via the endpoints. The endpoint is composed of 3 parts (collectively called as ABC's
of endpoint) as defines below: 
</p>
        <p>
          <strong>Address: </strong>The endpoints specify a Address that defines where the endpoint
is hosted. 
</p>
        <p>
          <strong>Contract: </strong>The endpoints specify a Contract that defines which methods
of the Service class will be accessible via the endpoint; each endpoint may expose
a different set of methods. 
</p>
        <p>
          <strong>Binding: </strong>The endpoints also define a binding that specifies how a
client will communicate with the service and the address where the endpoint is hosted.Various
components of the WCF are depicted in the figure below. 
</p>
        <p>
          <img alt="Screenshot - WCF_Arch.gif" src="http://www.codeproject.com/KB/webservices/Programming_WCF/WCF_Arch.gif" width="398" height="164" />
        </p>
        <p>
Who How What
</p>
        <p>
There are three types of contracts namely,
</p>
        <p>
          <strong>Service Contracts - </strong>Describes the operations a service can perform.
Maps CLR types to WSDL.<br /><strong>Data Contracts</strong> - Describes a data structure. Maps CLR types to XSD.<br /><strong>Messaga Contracts - </strong>Defines the structure of the message on the wire.
Maps CLR types to SOAP messages.
</p>
        <p>
Bindings can be defined in config file as well as programattically.
</p>
        <p>
Services have behaviors that control their concurrency, throttling, transactions,<br />
security, and other system semantics. 
</p>
        <p>
  
</p>
        <p>
Metadata in WCF refers to the information that describes precisely how to<br />
communicate with a service. Clients can request metadata from a running<br />
service to learn about their endpoints and the message formats that they 
</p>
        <p>
require. At design time, clients send a request message defined by the<br />
WS-MetadataExchange standard and receive WSDL in return. The WSDL<br />
can be used by the client to define a proxy class and configuration file that<br />
will later be used at runtime to communicate with the service. Figure 1.4<br />
shows this interaction. 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/WCFOverview_D799/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/WCFOverview_D799/image_thumb.png" width="424" height="205" />
          </a>
        </p>
        <p>
Use svcutil.exe to generate the proxy code
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=2e9d170a-7f75-410a-ba30-9d85e800ad61" />
      </body>
      <title>WCF Overview</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,2e9d170a-7f75-410a-ba30-9d85e800ad61.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,2e9d170a-7f75-410a-ba30-9d85e800ad61.aspx</link>
      <pubDate>Tue, 09 Mar 2010 20:17:35 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://www.codeproject.com/KB/webservices/Programming_WCF.aspx" href="http://www.codeproject.com/KB/webservices/Programming_WCF.aspx"&gt;http://www.codeproject.com/KB/webservices/Programming_WCF.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The WCF programming model unifies &lt;a href="http://en.wikipedia.org/wiki/Web_Services"&gt;Web
Services&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/.NET_Remoting"&gt;.NET Remoting&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Microsoft_Transaction_Server"&gt;Distributed
Transactions&lt;/a&gt;, and &lt;a href="http://en.wikipedia.org/wiki/Microsoft_Message_Queuing"&gt;Message
Queues&lt;/a&gt; into a single &lt;a href="http://en.wikipedia.org/wiki/Service-oriented_architecture"&gt;Service-oriented
programming&lt;/a&gt; model for &lt;a href="http://en.wikipedia.org/wiki/Distributed_computing"&gt;distributed
computing&lt;/a&gt;. WCF uses &lt;a href="http://en.wikipedia.org/wiki/SOAP"&gt;SOAP&lt;/a&gt; messages
for communication between two processes, thereby making WCF-based applications interoperable
with any other process that communicates via SOAP messages.
&lt;/p&gt;
&lt;p&gt;
A WCF Service is composed of three components parts viz, 
&lt;p&gt;
1) &lt;strong&gt;Service Class -&lt;/strong&gt; A WCF service class implements some service as
a set of methods. 
&lt;p&gt;
2) &lt;strong&gt;Host Environment&lt;/strong&gt; - A Host environment can be a Console application
or a Windows Service or a Windows Forms application or IIS as in case of the normal
asmx web service in .NET. 
&lt;p&gt;
3) &lt;strong&gt;Endpoints&lt;/strong&gt; - All communications with the WCF service will happen
via the endpoints. The endpoint is composed of 3 parts (collectively called as ABC's
of endpoint) as defines below: 
&lt;p&gt;
&lt;strong&gt;Address: &lt;/strong&gt;The endpoints specify a Address that defines where the endpoint
is hosted. 
&lt;p&gt;
&lt;strong&gt;Contract: &lt;/strong&gt;The endpoints specify a Contract that defines which methods
of the Service class will be accessible via the endpoint; each endpoint may expose
a different set of methods. 
&lt;p&gt;
&lt;strong&gt;Binding: &lt;/strong&gt;The endpoints also define a binding that specifies how a
client will communicate with the service and the address where the endpoint is hosted.Various
components of the WCF are depicted in the figure below. 
&lt;p&gt;
&lt;img alt="Screenshot - WCF_Arch.gif" src="http://www.codeproject.com/KB/webservices/Programming_WCF/WCF_Arch.gif" width="398" height="164"&gt; 
&lt;p&gt;
Who How What
&lt;/p&gt;
&lt;p&gt;
There are three types of contracts namely,
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Service Contracts - &lt;/strong&gt;Describes the operations a service can perform.
Maps CLR types to WSDL.&lt;br&gt;
&lt;strong&gt;Data Contracts&lt;/strong&gt; - Describes a data structure. Maps CLR types to XSD.&lt;br&gt;
&lt;strong&gt;Messaga Contracts - &lt;/strong&gt;Defines the structure of the message on the wire.
Maps CLR types to SOAP messages.
&lt;/p&gt;
&lt;p&gt;
Bindings can be defined in config file as well as programattically.
&lt;/p&gt;
&lt;p&gt;
Services have behaviors that control their concurrency, throttling, transactions,&lt;br&gt;
security, and other system semantics. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Metadata in WCF refers to the information that describes precisely how to&lt;br&gt;
communicate with a service. Clients can request metadata from a running&lt;br&gt;
service to learn about their endpoints and the message formats that they 
&lt;p&gt;
require. At design time, clients send a request message defined by the&lt;br&gt;
WS-MetadataExchange standard and receive WSDL in return. The WSDL&lt;br&gt;
can be used by the client to define a proxy class and configuration file that&lt;br&gt;
will later be used at runtime to communicate with the service. Figure 1.4&lt;br&gt;
shows this interaction. 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/WCFOverview_D799/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/WCFOverview_D799/image_thumb.png" width="424" height="205"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Use svcutil.exe to generate the proxy code
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=2e9d170a-7f75-410a-ba30-9d85e800ad61" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,2e9d170a-7f75-410a-ba30-9d85e800ad61.aspx</comments>
      <category>DotNet;Life / Career</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=389d2abf-ee9d-4921-8234-11cdc21b57e3</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,389d2abf-ee9d-4921-8234-11cdc21b57e3.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,389d2abf-ee9d-4921-8234-11cdc21b57e3.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=389d2abf-ee9d-4921-8234-11cdc21b57e3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#0000ff" size="3">
            <strong>Form 2.0 data binding</strong>
          </font>
        </p>
        <pre class="csharpcode">Binding nameBinding = <span class="kwrd">new</span> Binding(<span class="str">"Text"</span>, <span class="kwrd">this</span>.raceCarDriver, <span class="str">"Name"</span>, <span class="kwrd">true</span>); <span class="kwrd">this</span>.nameTextBox.DataBindings.Add(nameBinding);
or <span class="kwrd">this</span>.nameTextBox.DataBindings.Add( <span class="str">"Text"</span>, <span class="kwrd">this</span>.raceCarDriver, <span class="str">"Name"</span>);
The minimum implementation that <span class="kwrd">is</span> considered a list data
source by the Windows Forms binding engine <span class="kwrd">is</span> a <span class="kwrd">class</span> that
implements the IList <span class="kwrd">interface</span> (from System.Collections). <span class="kwrd">this</span>.BindingManager.Position
= 0; RefreshItems(); <span class="kwrd">this</span>.raceCarDriversListBox.DataSource
= <span class="kwrd">this</span>.raceCarDrivers; <span class="kwrd">this</span>.raceCarDriversListBox.DisplayMember
= <span class="str">"Name"</span>; <span class="kwrd">void</span> addButton_Click(<span class="kwrd">object</span> sender,
EventArgs e) { <span class="rem">// Add item to list data source directly</span> RaceCarDriver
raceCarDriver = <span class="kwrd">new</span> RaceCarDriver(<span class="str">"Nelson
Piquet"</span>, 300); <span class="kwrd">this</span>.raceCarDrivers.Add(raceCarDriver); <span class="rem">//
Select new item</span><span class="kwrd">this</span>.BindingManager.Position = <span class="kwrd">this</span>.BindingManager.Count
- 1; } <span class="kwrd">private</span><span class="kwrd">void</span> deleteButton_Click(<span class="kwrd">object</span> sender,
EventArgs e) { <span class="rem">// Remove item from list data source directly</span><span class="kwrd">this</span>.raceCarDrivers.Remove(
(RaceCarDriver)<span class="kwrd">this</span>.BindingManager.Current); }</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <pre>
        </pre>
        <p>
          <strong>BindingList&lt;T&gt;-&gt;IBindingList-&gt;IList</strong>
          <br />
BindingList&lt;T&gt; nicely implements the list management (AllowEdit, AllowNew, AllowRemove,
and AddNew) and change notification (SupportsChangeNotification, ListChanged) functional
subsets of IBindingList.<sup><a href="#ch16fn05">[5]</a></sup> And because it's generic,
it can turn any type into a strongly typed list data source with data-binding-savvy
list management and change notification using something like the following code<br /></p>
        <h6>Two-Way Item Change Synchronization
</h6>
        <p>
When the values in a DataGridView row are changed, DataGridView automatically replicates
the changes to the bound list data source. Similarly, when changes are made to an
item in the list data source of BindingList&lt;T&gt;, an item change notification
is broadcast to all bound controls. 
</p>
        <p>
  
</p>
        <p>
BindingList&lt;T&gt; allows us to use almost any class to create a data-binding-savvy
strongly typed list data source. However, some item classes come already associated
with their own collection classes. Although any collection class that implements IList
can be used as a list data source, you don't get full-flavor data binding if you don't
implement IBindingListnamely, support for two-way list and item change notification. 
</p>
        <p>
To gain this support and to avoid the highly involved implementation of IBindingList
ourselves, we'd love to be able to "upgrade" an existing IList implementation to IBindingList.
The class that performs this upgrade for you is <strong>BindingSource</strong>. 
</p>
        <p>
The BindingSource component (from System.Windows.Forms) consumes either item types
or list types and exposes them as IBindingList implementations. 
</p>
        <p>
  
</p>
        <p>
if you need to implement a VCR-type control to navigate the items in a data source,
you don't have to acquire a BindingManager and you don't have to manually create your
own navigation methods. Instead, you simply rely on the BindingSource to manage currency
and use its currency-oriented methods as required: 
</p>
        <p>
  
</p>
        <p>
void moveFirstButton_Click(object sender, EventArgs e) 
</p>
        <p>
{ this.employeesBindingSource.MoveFirst(); RefreshItems(); } 
</p>
        <p>
  
</p>
        <p>
Master-Detail binding<br /><a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/d0ca6d3651bd.Netreviewpart2_D671/image_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/d0ca6d3651bd.Netreviewpart2_D671/image_thumb.png" width="536" height="246" /></a></p>
        <p>
 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">Why [STAThread]</font>
          </strong>
        </p>
        <p>
          <code>When the STAThreadAttribute is applied, it changes the apartment state of the
current thread to be single threaded. Without getting into a huge discussion about
COM and threading, this attribute ensures the communication mechanism between the
current thread and other threads that may want to talk to it via COM. When you're
using Windows Forms, depending on the feature you're using, it may be using COM interop
in order to communicate with operating system components. Good examples of this are
the Clipboard and the File Dialogs.</code>
        </p>
        <p>
          <code>
            <font color="#0000ff" size="2">
              <strong>SingleInstanceApplication</strong>
            </font>
          </code>
        </p>
        <p>
// SingleInstanceApplication.cs 
<br />
class SingleInstanceApplication : <strong>WindowsFormsApplicationBase</strong><br />
{ ... protected override void OnCreateMainForm() { this.MainForm = new MainForm();
}<code><font color="#0000ff" size="2"><strong><br /></strong></font></code></p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=389d2abf-ee9d-4921-8234-11cdc21b57e3" />
      </body>
      <title>.Net review (part 2)</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,389d2abf-ee9d-4921-8234-11cdc21b57e3.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,389d2abf-ee9d-4921-8234-11cdc21b57e3.aspx</link>
      <pubDate>Fri, 05 Mar 2010 20:13:20 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font color="#0000ff" size="3"&gt;&lt;strong&gt;Form 2.0 data binding&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Binding nameBinding = &lt;span class="kwrd"&gt;new&lt;/span&gt; Binding(&lt;span class="str"&gt;"Text"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;.raceCarDriver, &lt;span class="str"&gt;"Name"&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;); &lt;span class="kwrd"&gt;this&lt;/span&gt;.nameTextBox.DataBindings.Add(nameBinding);
or &lt;span class="kwrd"&gt;this&lt;/span&gt;.nameTextBox.DataBindings.Add( &lt;span class="str"&gt;"Text"&lt;/span&gt;, &lt;span class="kwrd"&gt;this&lt;/span&gt;.raceCarDriver, &lt;span class="str"&gt;"Name"&lt;/span&gt;);
The minimum implementation that &lt;span class="kwrd"&gt;is&lt;/span&gt; considered a list data
source by the Windows Forms binding engine &lt;span class="kwrd"&gt;is&lt;/span&gt; a &lt;span class="kwrd"&gt;class&lt;/span&gt; that
implements the IList &lt;span class="kwrd"&gt;interface&lt;/span&gt; (from System.Collections). &lt;span class="kwrd"&gt;this&lt;/span&gt;.BindingManager.Position
= 0; RefreshItems(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.raceCarDriversListBox.DataSource
= &lt;span class="kwrd"&gt;this&lt;/span&gt;.raceCarDrivers; &lt;span class="kwrd"&gt;this&lt;/span&gt;.raceCarDriversListBox.DisplayMember
= &lt;span class="str"&gt;"Name"&lt;/span&gt;; &lt;span class="kwrd"&gt;void&lt;/span&gt; addButton_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
EventArgs e) { &lt;span class="rem"&gt;// Add item to list data source directly&lt;/span&gt; RaceCarDriver
raceCarDriver = &lt;span class="kwrd"&gt;new&lt;/span&gt; RaceCarDriver(&lt;span class="str"&gt;"Nelson
Piquet"&lt;/span&gt;, 300); &lt;span class="kwrd"&gt;this&lt;/span&gt;.raceCarDrivers.Add(raceCarDriver); &lt;span class="rem"&gt;//
Select new item&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.BindingManager.Position = &lt;span class="kwrd"&gt;this&lt;/span&gt;.BindingManager.Count
- 1; } &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; deleteButton_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender,
EventArgs e) { &lt;span class="rem"&gt;// Remove item from list data source directly&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.raceCarDrivers.Remove(
(RaceCarDriver)&lt;span class="kwrd"&gt;this&lt;/span&gt;.BindingManager.Current); }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;BindingList&amp;lt;T&amp;gt;-&amp;gt;IBindingList-&amp;gt;IList&lt;/strong&gt;
&lt;br&gt;
BindingList&amp;lt;T&amp;gt; nicely implements the list management (AllowEdit, AllowNew, AllowRemove,
and AddNew) and change notification (SupportsChangeNotification, ListChanged) functional
subsets of IBindingList.&lt;sup&gt;&lt;a href="#ch16fn05"&gt;[5]&lt;/a&gt;&lt;/sup&gt; And because it's generic,
it can turn any type into a strongly typed list data source with data-binding-savvy
list management and change notification using something like the following code&lt;br&gt;
&lt;/p&gt;
&lt;h6&gt;Two-Way Item Change Synchronization
&lt;/h6&gt;
&lt;p&gt;
When the values in a DataGridView row are changed, DataGridView automatically replicates
the changes to the bound list data source. Similarly, when changes are made to an
item in the list data source of BindingList&amp;lt;T&amp;gt;, an item change notification
is broadcast to all bound controls. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
BindingList&amp;lt;T&amp;gt; allows us to use almost any class to create a data-binding-savvy
strongly typed list data source. However, some item classes come already associated
with their own collection classes. Although any collection class that implements IList
can be used as a list data source, you don't get full-flavor data binding if you don't
implement IBindingListnamely, support for two-way list and item change notification. 
&lt;p&gt;
To gain this support and to avoid the highly involved implementation of IBindingList
ourselves, we'd love to be able to "upgrade" an existing IList implementation to IBindingList.
The class that performs this upgrade for you is &lt;strong&gt;BindingSource&lt;/strong&gt;. 
&lt;p&gt;
The BindingSource component (from System.Windows.Forms) consumes either item types
or list types and exposes them as IBindingList implementations. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
if you need to implement a VCR-type control to navigate the items in a data source,
you don't have to acquire a BindingManager and you don't have to manually create your
own navigation methods. Instead, you simply rely on the BindingSource to manage currency
and use its currency-oriented methods as required: 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
void moveFirstButton_Click(object sender, EventArgs e) 
&lt;p&gt;
{ this.employeesBindingSource.MoveFirst(); RefreshItems(); } 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Master-Detail binding&lt;br&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/d0ca6d3651bd.Netreviewpart2_D671/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/d0ca6d3651bd.Netreviewpart2_D671/image_thumb.png" width="536" height="246"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font color="#0000ff" size="2"&gt;Why [STAThread]&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;When the STAThreadAttribute is applied, it changes the apartment state of the
current thread to be single threaded. Without getting into a huge discussion about
COM and threading, this attribute ensures the communication mechanism between the
current thread and other threads that may want to talk to it via COM. When you're
using Windows Forms, depending on the feature you're using, it may be using COM interop
in order to communicate with operating system components. Good examples of this are
the Clipboard and the File Dialogs.&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;&lt;font color="#0000ff" size="2"&gt;&lt;strong&gt;SingleInstanceApplication&lt;/strong&gt;&lt;/font&gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
// SingleInstanceApplication.cs 
&lt;br&gt;
class SingleInstanceApplication : &lt;strong&gt;WindowsFormsApplicationBase&lt;/strong&gt; 
&lt;br&gt;
{ ... protected override void OnCreateMainForm() { this.MainForm = new MainForm();
}&lt;code&gt;&lt;font color="#0000ff" size="2"&gt;&lt;strong&gt;
&lt;br&gt;
&lt;/p&gt;
&gt;&gt;&gt;&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=389d2abf-ee9d-4921-8234-11cdc21b57e3" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,389d2abf-ee9d-4921-8234-11cdc21b57e3.aspx</comments>
      <category>DotNet;Life / Career</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>
            <font color="#0000ff">CLR and .NET Framework</font>
          </strong>
        </p>
        <p>
The CLR is the runtime for executing managed code. C# is one of several managed<br />
languages that get compiled into managed code. Managed code is packaged into an<br />
assembly, in the form of either an executable file (an .exe) or a library (a .dll),
along<br />
with type information, or metadata.<br /><br />
Managed code is represented in Intermediate Language or IL. When the CLR loads<br />
an assembly, it converts the IL into the native code of the machine, such as x86.
This<br />
conversion is done by the CLR’s JIT (Just-In-Time) compiler. An assembly retains 
</p>
        <p>
almost all of the original source language constructs, which makes it easy to inspect<br />
and even generate code dynamically.<br /></p>
        <p>
The CLR performs as a host for numerous runtime services. Examples of these services<br />
include memory management, the loading of libraries, and security services.<br />
The CLR is language-neutral, allowing developers to build applications in multiple<br />
languages (e.g., C#, Visual Basic .NET, Managed C++, Delphi.NET, Chrome .NET,<br />
and J#). 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font color="#0000ff">How the Garbage Collector Works:</font>
          </strong>
        </p>
        <p>
The GC begins with its root object references, and walks the object graph, marking<br />
all the objects it touches as reachable. Once this process is complete, all objects
that<br />
have not been marked are considered unused, and are subject to garbage collection.<br />
Unused objects without finalizers are immediately discarded; unused objects with<br />
finalizers are enqueued for processing on the finalizer thread after the GC is complete.<br />
These objects then become eligible for collection in the next GC for the object’s<br />
generation (unless resurrected). 
</p>
        <p>
  
</p>
        <p>
The remaining “live” objects are then shifted to the start of the heap (compacted),<br />
freeing space for more objects. This compaction serves two purposes: it avoids 
</p>
        <p>
memory fragmentation, and it allows the GC to employ a very simple strategy when<br />
allocating new objects, which is to always allocate memory at the end of the heap.<br />
This avoids the potentially time-consuming task of maintaining a list of free memory<br />
segments. 
</p>
        <p>
  
</p>
        <p>
If there is insufficient space to allocate memory for a new object after garbage<br />
collection, and the operating system is unable to grant further memory, an<br />
OutOfMemoryException is thrown. 
</p>
        <p>
  
</p>
        <p>
          <em>Generational collection<br /></em>The most important optimization is that the GC is generational. This takes advantage<br />
of the fact that although many objects are allocated and discarded rapidly, certain<br />
objects are long-lived and thus don’t need to be traced during every collection.<br />
Basically, the GC divides the managed heap into three generations. Objects that have<br />
just been allocated are in Gen0 and objects that have survived one collection cycle<br />
are in Gen1; all other objects are in Gen2. 
</p>
        <p>
  
</p>
        <p>
          <em>The large object heap</em>
          <br />
The GC uses a separate heap called the Large Object Heap (LOH) for objects larger<br />
than a certain threshold (currently 85,000 bytes). This avoids excessive Gen0<br />
collections—without the LOH, allocating a series of 16 MB objects might trigger a<br />
Gen0 collection after every allocation. 
</p>
        <p>
The LOH is not subject to compaction, because moving large blocks of memory<br />
during garbage collection would be prohibitively expensive. This has two<br />
consequences: 
</p>
        <p>
1. Allocations can be slower<br />
2. The LOH is subject to fragmentation 
</p>
        <p>
The large object heap is also nongenerational: all objects are treated as Gen2. 
</p>
        <p>
  
</p>
        <p>
          <em>Concurrent and background collection</em>
        </p>
        <p>
The GC must freeze (block) your execution threads for periods during a collection.<br />
This includes the entire period during which a Gen0 or Gen1 collection takes place.<br />
The GC makes a special attempt, though, at allowing threads to run during a Gen2<br />
collection 
</p>
        <p>
  
</p>
        <p>
Forcing Garbage Collection (not recommend) 
</p>
        <p>
GC.Collect() 
</p>
        <p>
  
</p>
        <p>
          <strong>A good guideline is to implement IDisposable yourself if any field in your
class is assigned an object that implements IDisposable. </strong>(Such as System.Timers.Timer)(System.Threading.Timer
is different) 
</p>
        <p>
  
</p>
        <p>
Monitor the memory leaks: long memoryUsed = GC.GetTotalMemory (true); 
</p>
        <p>
  
</p>
        <p>
Occasionally, it’s useful to hold a reference to an object that’s “invisible” to the
GC<br />
in terms of keeping the object alive. This is called a <strong><font color="#0000ff">weak
reference</font></strong>, and is implemented<br />
by the System.WeakReference class. 
</p>
        <p>
  
</p>
        <p>
One use for WeakReference is to cache large object graphs.<br /><a title="http://www.shafqatahmed.com/2008/01/weakreference-b.html" href="http://www.shafqatahmed.com/2008/01/weakreference-b.html">http://www.shafqatahmed.com/2008/01/weakreference-b.html</a></p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font color="#0000ff">Asynchronous Methods</font>
          </strong>
        </p>
        <p>
asynchronous programming model or APM<br /></p>
        <p>
An asynchronous method aims never to block any thread, instead using a pattern of<br />
returning with a callback. 
</p>
        <p>
  
</p>
        <p>
The end goal of the APM is thread economy. 
</p>
        <p>
The purpose of asynchronous methods isn’t to<br />
provide a convenient mechanism for executing a method in parallel with the caller;<br />
it’s to optimize thread resources. 
</p>
        <p>
  
</p>
        <p>
Here’s the golden rule of the APM: <strong>Make good use of the CPU, or exit with
a callback!</strong></p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
The primary use for asynchronous methods is handling many potentially longrunning<br />
concurrent requests—typically over slow network connections. 
</p>
        <p>
  
</p>
        <p>
IAsyncResult BeginXXX (in/ref-args, AsyncCallback callback, object state);<br />
return-type EndXXX (out/ref-args, IAsyncResult asyncResult);<br />
public delegate void AsyncCallback (IAsyncResult ar); 
</p>
        <p>
  
</p>
        <p>
To avoid blocking, you will nearly always call the EndXXX method from inside the<br />
callback method. Callbacks always run on pooled threads. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb.png" width="574" height="192" />
          </a>
        </p>
        <p>
  
</p>
        <p>
          <a title="http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls" href="http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls">http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls</a>
          <br />
          <a title="http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx" href="http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx">http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx</a>
        </p>
        <p>
          <font color="#0000ff" size="3">Collections</font>
        </p>
        <p>
ICollection Properties
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb_2.png" width="510" height="253" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb_1.png" width="557" height="198" />
          </a>
        </p>
        <p>
IComparer 
<br />
Copmare method
</p>
        <p>
IEqualityComparer<br />
GetHashCode, Equals
</p>
        <p>
SortedList calss is a dictionary.
</p>
        <p>
          <font color="#0000ff" size="2">
            <strong>Race conditions and deadlocks</strong>
          </font>
        </p>
        <p>
        </p>
        <p>
          <a title="http://support.microsoft.com/kb/317723" href="http://support.microsoft.com/kb/317723">http://support.microsoft.com/kb/317723</a>
        </p>
        <p>
A <i>race condition</i> occurs when two threads access a shared variable at the same
time. The first thread reads the variable, and the second thread reads the same value
from the variable. Then the first thread and second thread perform their operations
on the value, and they race to see which thread can write the value last to the shared
variable. The value of the thread that writes its value last is preserved, because
the thread is writing over the value that the previous thread wrote.
</p>
        <p>
A <i>deadlock</i> occurs when two threads each lock a different variable at the same
time and then try to lock the variable that the other thread already locked. As a
result, each thread stops executing and waits for the other thread to release the
variable. Because each thread is holding the variable that the other thread wants,
nothing occurs, and the threads remain deadlocked.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4" />
      </body>
      <title>.Net review 1</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4.aspx</link>
      <pubDate>Thu, 04 Mar 2010 19:57:29 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;&lt;font color="#0000ff"&gt;CLR and .NET Framework&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The CLR is the runtime for executing managed code. C# is one of several managed&lt;br&gt;
languages that get compiled into managed code. Managed code is packaged into an&lt;br&gt;
assembly, in the form of either an executable file (an .exe) or a library (a .dll),
along&lt;br&gt;
with type information, or metadata.&lt;br&gt;
&lt;br&gt;
Managed code is represented in Intermediate Language or IL. When the CLR loads&lt;br&gt;
an assembly, it converts the IL into the native code of the machine, such as x86.
This&lt;br&gt;
conversion is done by the CLR’s JIT (Just-In-Time) compiler. An assembly retains 
&lt;p&gt;
almost all of the original source language constructs, which makes it easy to inspect&lt;br&gt;
and even generate code dynamically.&lt;br&gt;
&lt;p&gt;
The CLR performs as a host for numerous runtime services. Examples of these services&lt;br&gt;
include memory management, the loading of libraries, and security services.&lt;br&gt;
The CLR is language-neutral, allowing developers to build applications in multiple&lt;br&gt;
languages (e.g., C#, Visual Basic .NET, Managed C++, Delphi.NET, Chrome .NET,&lt;br&gt;
and J#). 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;&lt;font color="#0000ff"&gt;How the Garbage Collector Works:&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The GC begins with its root object references, and walks the object graph, marking&lt;br&gt;
all the objects it touches as reachable. Once this process is complete, all objects
that&lt;br&gt;
have not been marked are considered unused, and are subject to garbage collection.&lt;br&gt;
Unused objects without finalizers are immediately discarded; unused objects with&lt;br&gt;
finalizers are enqueued for processing on the finalizer thread after the GC is complete.&lt;br&gt;
These objects then become eligible for collection in the next GC for the object’s&lt;br&gt;
generation (unless resurrected). 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The remaining “live” objects are then shifted to the start of the heap (compacted),&lt;br&gt;
freeing space for more objects. This compaction serves two purposes: it avoids 
&lt;p&gt;
memory fragmentation, and it allows the GC to employ a very simple strategy when&lt;br&gt;
allocating new objects, which is to always allocate memory at the end of the heap.&lt;br&gt;
This avoids the potentially time-consuming task of maintaining a list of free memory&lt;br&gt;
segments. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
If there is insufficient space to allocate memory for a new object after garbage&lt;br&gt;
collection, and the operating system is unable to grant further memory, an&lt;br&gt;
OutOfMemoryException is thrown. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;em&gt;Generational collection&lt;br&gt;
&lt;/em&gt;The most important optimization is that the GC is generational. This takes advantage&lt;br&gt;
of the fact that although many objects are allocated and discarded rapidly, certain&lt;br&gt;
objects are long-lived and thus don’t need to be traced during every collection.&lt;br&gt;
Basically, the GC divides the managed heap into three generations. Objects that have&lt;br&gt;
just been allocated are in Gen0 and objects that have survived one collection cycle&lt;br&gt;
are in Gen1; all other objects are in Gen2. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;em&gt;The large object heap&lt;/em&gt;
&lt;br&gt;
The GC uses a separate heap called the Large Object Heap (LOH) for objects larger&lt;br&gt;
than a certain threshold (currently 85,000 bytes). This avoids excessive Gen0&lt;br&gt;
collections—without the LOH, allocating a series of 16 MB objects might trigger a&lt;br&gt;
Gen0 collection after every allocation. 
&lt;p&gt;
The LOH is not subject to compaction, because moving large blocks of memory&lt;br&gt;
during garbage collection would be prohibitively expensive. This has two&lt;br&gt;
consequences: 
&lt;p&gt;
1. Allocations can be slower&lt;br&gt;
2. The LOH is subject to fragmentation 
&lt;p&gt;
The large object heap is also nongenerational: all objects are treated as Gen2. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;em&gt;Concurrent and background collection&lt;/em&gt; 
&lt;p&gt;
The GC must freeze (block) your execution threads for periods during a collection.&lt;br&gt;
This includes the entire period during which a Gen0 or Gen1 collection takes place.&lt;br&gt;
The GC makes a special attempt, though, at allowing threads to run during a Gen2&lt;br&gt;
collection 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Forcing Garbage Collection (not recommend) 
&lt;p&gt;
GC.Collect() 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;A good guideline is to implement IDisposable yourself if any field in your
class is assigned an object that implements IDisposable. &lt;/strong&gt;(Such as System.Timers.Timer)(System.Threading.Timer
is different) 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Monitor the memory leaks: long memoryUsed = GC.GetTotalMemory (true); 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Occasionally, it’s useful to hold a reference to an object that’s “invisible” to the
GC&lt;br&gt;
in terms of keeping the object alive. This is called a &lt;strong&gt;&lt;font color="#0000ff"&gt;weak
reference&lt;/font&gt;&lt;/strong&gt;, and is implemented&lt;br&gt;
by the System.WeakReference class. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
One use for WeakReference is to cache large object graphs.&lt;br&gt;
&lt;a title="http://www.shafqatahmed.com/2008/01/weakreference-b.html" href="http://www.shafqatahmed.com/2008/01/weakreference-b.html"&gt;http://www.shafqatahmed.com/2008/01/weakreference-b.html&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;&lt;font color="#0000ff"&gt;Asynchronous Methods&lt;/font&gt;&lt;/strong&gt; 
&lt;p&gt;
asynchronous programming model or APM&lt;br&gt;
&lt;p&gt;
An asynchronous method aims never to block any thread, instead using a pattern of&lt;br&gt;
returning with a callback. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The end goal of the APM is thread economy. 
&lt;p&gt;
The purpose of asynchronous methods isn’t to&lt;br&gt;
provide a convenient mechanism for executing a method in parallel with the caller;&lt;br&gt;
it’s to optimize thread resources. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Here’s the golden rule of the APM: &lt;strong&gt;Make good use of the CPU, or exit with
a callback!&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp; 
&lt;p&gt;
The primary use for asynchronous methods is handling many potentially longrunning&lt;br&gt;
concurrent requests—typically over slow network connections. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
IAsyncResult BeginXXX (in/ref-args, AsyncCallback callback, object state);&lt;br&gt;
return-type EndXXX (out/ref-args, IAsyncResult asyncResult);&lt;br&gt;
public delegate void AsyncCallback (IAsyncResult ar); 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
To avoid blocking, you will nearly always call the EndXXX method from inside the&lt;br&gt;
callback method. Callbacks always run on pooled threads. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb.png" width="574" height="192"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a title="http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls" href="http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls"&gt;http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx" href="http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx"&gt;http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="3"&gt;Collections&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
ICollection Properties
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb_2.png" width="510" height="253"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb_1.png" width="557" height="198"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
IComparer 
&lt;br&gt;
Copmare method
&lt;/p&gt;
&lt;p&gt;
IEqualityComparer&lt;br&gt;
GetHashCode, Equals
&lt;/p&gt;
&lt;p&gt;
SortedList calss is a dictionary.
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2"&gt;&lt;strong&gt;Race conditions and deadlocks&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://support.microsoft.com/kb/317723" href="http://support.microsoft.com/kb/317723"&gt;http://support.microsoft.com/kb/317723&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
A &lt;i&gt;race condition&lt;/i&gt; occurs when two threads access a shared variable at the same
time. The first thread reads the variable, and the second thread reads the same value
from the variable. Then the first thread and second thread perform their operations
on the value, and they race to see which thread can write the value last to the shared
variable. The value of the thread that writes its value last is preserved, because
the thread is writing over the value that the previous thread wrote.
&lt;/p&gt;
&lt;p&gt;
A &lt;i&gt;deadlock&lt;/i&gt; occurs when two threads each lock a different variable at the same
time and then try to lock the variable that the other thread already locked. As a
result, each thread stops executing and waits for the other thread to release the
variable. Because each thread is holding the variable that the other thread wants,
nothing occurs, and the threads remain deadlocked.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4.aspx</comments>
      <category>DotNet;Life / Career</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://msdn.microsoft.com/en-us/library/ms951089.aspx" href="http://msdn.microsoft.com/en-us/library/ms951089.aspx">http://msdn.microsoft.com/en-us/library/ms951089.aspx</a>
          <br />
          <a title="http://msdn.microsoft.com/en-us/library/ms951109.aspx" href="http://msdn.microsoft.com/en-us/library/ms951109.aspx">http://msdn.microsoft.com/en-us/library/ms951109.aspx</a>
          <br />
          <a title="http://msdn.microsoft.com/en-us/library/ms951109.aspx" href="http://msdn.microsoft.com/en-us/library/ms951109.aspx">http://msdn.microsoft.com/en-us/library/ms951109.aspx</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5" />
      </body>
      <title>Windows Form Threading Programming</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5.aspx</link>
      <pubDate>Wed, 03 Mar 2010 21:59:53 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/ms951089.aspx" href="http://msdn.microsoft.com/en-us/library/ms951089.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms951089.aspx&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/ms951109.aspx" href="http://msdn.microsoft.com/en-us/library/ms951109.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms951109.aspx&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/ms951109.aspx" href="http://msdn.microsoft.com/en-us/library/ms951109.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms951109.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=47029548-3412-4c13-b495-b61959095cb3</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,47029548-3412-4c13-b495-b61959095cb3.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,47029548-3412-4c13-b495-b61959095cb3.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=47029548-3412-4c13-b495-b61959095cb3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.c-sharpcorner.com/UploadFile/scottlysle/WordProcessor02042007234628PM/WordProcessor.aspx" href="http://www.c-sharpcorner.com/UploadFile/scottlysle/WordProcessor02042007234628PM/WordProcessor.aspx">http://www.c-sharpcorner.com/UploadFile/scottlysle/WordProcessor02042007234628PM/WordProcessor.aspx</a>
          <br />
          <a title="http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx" href="http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx">http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx</a>
          <br />
          <a title="http://www.codeproject.com/KB/edit/RicherTextBox1.aspx" href="http://www.codeproject.com/KB/edit/RicherTextBox1.aspx">http://www.codeproject.com/KB/edit/RicherTextBox1.aspx</a>
          <br />
          <a title="http://www.codeproject.com/KB/cs/eRichTextBox.aspx" href="http://www.codeproject.com/KB/cs/eRichTextBox.aspx">http://www.codeproject.com/KB/cs/eRichTextBox.aspx</a>
          <br />
          <a title="http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx" href="http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx">http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=47029548-3412-4c13-b495-b61959095cb3" />
      </body>
      <title>Extend Richtextbox control</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,47029548-3412-4c13-b495-b61959095cb3.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,47029548-3412-4c13-b495-b61959095cb3.aspx</link>
      <pubDate>Tue, 23 Feb 2010 02:54:02 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://www.c-sharpcorner.com/UploadFile/scottlysle/WordProcessor02042007234628PM/WordProcessor.aspx" href="http://www.c-sharpcorner.com/UploadFile/scottlysle/WordProcessor02042007234628PM/WordProcessor.aspx"&gt;http://www.c-sharpcorner.com/UploadFile/scottlysle/WordProcessor02042007234628PM/WordProcessor.aspx&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx" href="http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx"&gt;http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://www.codeproject.com/KB/edit/RicherTextBox1.aspx" href="http://www.codeproject.com/KB/edit/RicherTextBox1.aspx"&gt;http://www.codeproject.com/KB/edit/RicherTextBox1.aspx&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://www.codeproject.com/KB/cs/eRichTextBox.aspx" href="http://www.codeproject.com/KB/cs/eRichTextBox.aspx"&gt;http://www.codeproject.com/KB/cs/eRichTextBox.aspx&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx" href="http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx"&gt;http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=47029548-3412-4c13-b495-b61959095cb3" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,47029548-3412-4c13-b495-b61959095cb3.aspx</comments>
      <category>DotNet;Projects</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=ec11bc1e-7165-48bc-8ff0-dc240bb09445</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,ec11bc1e-7165-48bc-8ff0-dc240bb09445.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,ec11bc1e-7165-48bc-8ff0-dc240bb09445.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ec11bc1e-7165-48bc-8ff0-dc240bb09445</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Setting the value will force future processes in that space to use the specified .NET
runtime, like: 
</p>
        <p>
          <code>set COMPLUS_Version = v3.5</code>
        </p>
        <p>
That would force everything to run in .NET 3.5.
</p>
        <p>
          <a title="http://www.cookcomputing.com/blog/archives/000597.html" href="http://www.cookcomputing.com/blog/archives/000597.html">http://www.cookcomputing.com/blog/archives/000597.html</a>
        </p>
        <p>
It is not necessary to rebuild NUnit. I discovered that if you add the following to
the relevant NUnit application config file you can run a test dll built for .NET 4.0.
Under &lt;configuration&gt; add: 
</p>
        <pre>&lt;startup&gt;
  &lt;requiredRuntime version="v4.0.20506" /&gt;
&lt;/startup&gt;
</pre>
        <p>
and under &lt;runtime&gt; add: 
</p>
        <pre>&lt;loadFromRemoteSources enabled="true" /&gt;
</pre>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=ec11bc1e-7165-48bc-8ff0-dc240bb09445" />
      </body>
      <title>NUnit and COMPLUS_Version Environment Variable</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,ec11bc1e-7165-48bc-8ff0-dc240bb09445.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,ec11bc1e-7165-48bc-8ff0-dc240bb09445.aspx</link>
      <pubDate>Wed, 27 Jan 2010 15:49:24 GMT</pubDate>
      <description>&lt;p&gt;
Setting the value will force future processes in that space to use the specified .NET
runtime, like: 
&lt;p&gt;
&lt;code&gt;set COMPLUS_Version = v3.5&lt;/code&gt; 
&lt;p&gt;
That would force everything to run in .NET 3.5.
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://www.cookcomputing.com/blog/archives/000597.html" href="http://www.cookcomputing.com/blog/archives/000597.html"&gt;http://www.cookcomputing.com/blog/archives/000597.html&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
It is not necessary to rebuild NUnit. I discovered that if you add the following to
the relevant NUnit application config file you can run a test dll built for .NET 4.0.
Under &amp;lt;configuration&amp;gt; add: 
&lt;/p&gt;
&lt;pre&gt;&amp;lt;startup&amp;gt;
  &amp;lt;requiredRuntime version="v4.0.20506" /&amp;gt;
&amp;lt;/startup&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
and under &amp;lt;runtime&amp;gt; add: &lt;pre&gt;&amp;lt;loadFromRemoteSources enabled="true" /&amp;gt;
&lt;/pre&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=ec11bc1e-7165-48bc-8ff0-dc240bb09445" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,ec11bc1e-7165-48bc-8ff0-dc240bb09445.aspx</comments>
      <category>DotNet;Tricks</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=8de2cc59-7159-4e28-a5c9-4fe776be0782</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,8de2cc59-7159-4e28-a5c9-4fe776be0782.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,8de2cc59-7159-4e28-a5c9-4fe776be0782.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8de2cc59-7159-4e28-a5c9-4fe776be0782</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>
            <font size="2">(By Eric Evan)</font>
          </strong>
        </p>
        <p>
          <strong>
            <font size="2">Chapter 1 What Is Domain-Driven Design</font>
          </strong>
        </p>
        <p>
When we begin a software project, we should focus on the domain it is operating in.
The entire purpose of the software is to enhance a specific domain. 
</p>
        <p>
How can we make the software fit harmoniously with the domain? The best way to do
it is to make software a reflection of the domain.<br /></p>
        <p>
The model is our internal representation of the target domain, and it is very necessary
throughout the design and the development process.
</p>
        <p>
There are different approaches to software design. One is the waterfall design method.
This method involves a number of stages. The business experts put up a set of requirements
which are communicated to the business analysts. The analysts create a model based
on those requirements, and pass the results to the developers, who start coding based
on what they have received. It’s a one way flow of knowledge. While this has been
a traditional approach in software design, and has been used with a certain level
of success over the years, it has its flaws and limits. The main problem is that there
is no feedback from the analysts to the business experts or from the developers to
the analysts. Another approach is the Agile methodologies, such as Extreme Programming
(XP). These methodologies are a collective movement against the waterfall approach,
resulting from the difficulties of trying to come up with all the requirements upfront,
particularly in light of requirements change. It’s really hard to create a complete
model which covers all aspects of a domain upfront. It takes a lot of thinking, and
often you just cannot see all the issues involved from the beginning, nor can you
foresee some of the negative side effects or mistakes of your design. Another problem
Agile attempts to solve is the so called “analysis paralysis”, with team members so
afraid of making any design decisions that they make no progress at all. While Agile
advocates recognize the importance of design decision, they resist upfront design.
Instead they employ a great deal of implementation flexibility, and through iterative
development with continuous business stakeholder participation and a lot of refactoring,
the development team gets to learn more about the customer domain and can better produce
software that meets the customers needs. 
</p>
        <p>
  
</p>
        <p>
The Agile methods have their own problems and limitations; they advocate simplicity,
but everybody has their own view of what that means. Also, continuous refactoring
done by developers without solid design principles will produce code that is hard
to understand or change. And while the waterfall approach may lead to over-engineering,
the fear of overengineering may lead to another fear: the fear of doing a deep, thoroughly
thought out design. 
</p>
        <p>
  
</p>
        <p>
          <font size="2">
            <strong>Chapter 2 The Ubiquitous Language</strong>
          </font>
        </p>
        <p>
A core principle of domain-driven design is to use a language based on the model.
Since the model is the common ground, the place where the software meets the domain,
it is appropriate to use it as the building ground for this language. 
</p>
        <p>
Building a language like that has a clear outcome: the model and the language are
strongly interconnected with one another. A change in the language should become a
change to the model. 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <font size="2">
            <strong>Chapter 3 Model-Driven Design</strong>
          </font>
        </p>
        <p>
A better approach is to closely relate domain modeling and design. The model should
be constructed with an eye open to the software and design considerations. Developers
should be included in the modeling process. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb_2.png" width="792" height="564" />
          </a>
        </p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb_3.png" width="735" height="420" />
          </a>
        </p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_10.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb_4.png" width="660" height="469" />
          </a>
        </p>
        <p>
  
</p>
        <p>
          <strong>Entities</strong>: There is a category of objects which seem to have an identity,
which remains the same throughout the states of the software. For these objects it
is not the attributes which matter, but a thread of continuity and identity, which
spans the life of a system and can extend beyond it. Such objects are called Entities. 
</p>
        <p>
  
</p>
        <p>
          <strong>Value Objects</strong>:  There are cases when we need to contain some
attributes of a domain element. We are not interested in which object it is, but what
attributes it has. An object that is used to describe certain aspects of a domain,
and which does not have identity, is named Value Object. 
</p>
        <p>
It is highly recommended that value objects be immutable.<br />
One golden rule is: if Value Objects are shareable, they should be immutable. Value
Objects should be kept thin and simple. When a Value Object is needed by another party,
it can be simply passed by value, or a copy of it can be created and given. 
</p>
        <p>
  
</p>
        <p>
          <strong>Services</strong>: 
</p>
        <p>
we discover that some aspects of the domain are not easily mapped to objects. 
But there are some actions in the domain, some verbs, which do not seem to belong
to any object. They represent an important behavior of the domain, so they cannot
be neglected or simply incorporated into some of the Entities or Value Objects. When
such a behavior is recognized in the domain, the best practice is to declare it as
a Service. Such an object does not have an internal state, and its purpose is to simply
provide functionality for the domain. The assistance provided by a Service can be
a significant one, and a Service can group related functionality which serves the
Entities and the Value Objects. 
</p>
        <p>
(For example, to transfer money from one account to another; should that function
be in the sending account or the receiving account? It feels just as misplaced in
either.) 
</p>
        <p>
There are three characteristics of a Service:<br />
1. The operation performed by the Service refers to a domain concept which does not
naturally belong to an Entity or Value<br />
Object.<br />
2. The operation performed refers to other objects in the domain.<br />
3. The operation is stateless. 
</p>
        <p>
  
</p>
        <p>
          <strong>Modules</strong>: it is necessary to organize the model into modules. Modules
are used as a method of organizing related concepts and tasks in order to reduce complexity. 
<br /></p>
        <p>
Another reason for using modules is related to code quality. It is widely accepted
that software code should have <strong>a high level of cohesion and a low level of
coupling</strong>.<br /></p>
        <p>
Two of the most used are <strong>communicational cohesion and functional cohesion</strong>. 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>Three patterns:  Aggregate is a domain pattern used to define object
ownership and boundaries. Factories and Repositories are two design patterns which
help us deal with object creation and storage.</strong>
        </p>
        <p>
  
</p>
        <p>
An <strong>Aggregate</strong> is a group of associated objects which are considered
as one unit with regard to data changes. 
</p>
        <p>
  
</p>
        <p>
The root is an Entity, and it is the only object accessible from outside. The root
can hold references to any of the aggregate objects, and the other objects can hold
references to each other, but an outside object can hold references only to the root
object. 
</p>
        <p>
Cluster the Entities and Value Objects into Aggregates and define boundaries around
each. Choose one Entity to be the root of each Aggregate, and control all access to
the objects inside the boundary through the root. Allow external objects to hold references
to the root only. Transient references to internal members can be passed out for use
within a single operation only. 
</p>
        <p>
  
</p>
        <p>
          <strong>Factories</strong> are used to encapsulate the knowledge necessary for object
creation, and they are especially useful to create Aggregates. When the root of the
Aggregate is created, all the objects contained by the Aggregate are created along
with it, and all the invariants are enforced.<br />
A Factory Method is an object method which contains and hides knowledge necessary
to create another object. 
</p>
        <p>
  
</p>
        <p>
There are times when a Factory is not needed, and a simple constructor is enough.
Use a constructor when:<br />
• The construction is not complicated.<br />
• The creation of an object does not involve the creation of others, and all the attributes
needed are passed via the constructor.<br />
• The client is interested in the implementation, perhaps wants to choose the Strategy
used.<br />
• The class is the type. There is no hierarchy involved, so no need to choose between
a list of concrete implementations. 
</p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
  
</p>
        <p>
Therefore, use a <strong>Repository</strong>, the purpose of which is to encapsulate
all the logic needed to obtain object references. 
</p>
        <p>
The overall effect is that the domain model is decoupled from the need of storing
objects or their references, and accessing the<br />
underlying persistence infrastructure. Provide repositories only for Aggregate roots
that actually need direct access. Keep the client focused on the model, delegating
all object storage and access to the Repositories. 
</p>
        <p>
  
</p>
        <p>
There is a relationship between Factory and Repository. They are both patterns of
the model-driven design, and they both help us to manage the life cycle of domain
objects. While the Factory is concerned with the creation of objects, the Repository
takes care of already existing objects. 
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font size="2">Chapter 4 Refactoring Toward Deeper Insight</font>
          </strong>
        </p>
        <p>
          <strong>
            <font size="2">
            </font>
          </strong>  
</p>
        <p>
One of the first things we are taught about modeling is to read the business specifications
and look for nouns and verbs. The nouns are converted to classes, while the verbs
become methods. This is a simplification, and will lead to a <strong>shallow</strong> model. 
</p>
        <p>
We start with a coarse, shallow model. Then we refine it and the design based on deeper
knowledge about the domain, on a better understanding of the concerns. We add new
concepts and abstractions to it. The design is then refactored. Each refinement adds
more clarity to the design. This creates in turn the premises for a Breakthrough. 
</p>
        <p>
  
</p>
        <p>
To reach a Breakthrough, we need to make the implicit concepts explicit.<br /></p>
        <p>
The first way to discover implicit concepts is to listen to the language.<br /></p>
        <p>
Try to see if there is a missing concept. 
</p>
        <p>
  
</p>
        <p>
Another obvious way of digging out model concepts is to use domain literature. 
</p>
        <p>
  
</p>
        <p>
There are other concepts which are very useful when made explicit: Constraint, Process
and Specification.<br /></p>
        <p>
Placing the Constraint into a separate method has the advantage of making it explicit. 
<br />
Processes are usually expressed in code with procedures.<br />
Simply said, a Specification is used to test an object to see if it satisfies a certain
criteria. The domain layer contains business rules which are applied to Entities and
Value Objects. Those rules are usually incorporated into the objects they apply to.
When rule is not a simple method and spans many entities and value objects, 
the rule should be encapsulated into an object of its own, which becomes the Specification
of the Customer, and should be kept in the domain layer. 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font size="2">Chapter 5 Preserving Model Integrity</font>
          </strong>
        </p>
        <p>
  
</p>
        <p>
This chapter is about large projects which require the combined efforts of multiple
teams. 
</p>
        <p>
  
</p>
        <p>
Instead of trying to keep one big model that will fall apart later, we should consciously
divide it into several models. 
</p>
        <p>
Each model should have a clearly delimited border, and the relationships between models
should be defined with precision. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb.png" width="731" height="381" />
          </a>
        </p>
        <p>
  
</p>
        <p>
A model should be small enough to be assigned to one team. 
</p>
        <p>
  
</p>
        <p>
          <strong>Bounded Context</strong>: The main idea is to define the scope of a model,
to draw up the boundaries of its context, then do the most possible to keep the model
unified.<br />
Explicitly set boundaries in terms of team organization, usage within specific parts
of the application, and physical manifestations such as code bases and database schemas.
Keep the model strictly consistent within these bounds, but don’t be distracted or
confused by issues outside. 
</p>
        <p>
A Bounded Context is not a Module. A Bounded Context provides the logical frame inside
of which the model evolves. Modules are used to organize the elements of a model,
so Bounded Context encompasses the Module. 
</p>
        <p>
  
</p>
        <p>
A <strong>Context Map</strong> is a document which outlines the different Bounded
Contexts and the relationships between them. What it is important is that everyone
working on the project shares and understands it. 
</p>
        <p>
  
</p>
        <p>
A common practice is to define the contexts, then create modules for each context,
and use a naming convention to indicate the context each module belongs to. 
</p>
        <p>
  
</p>
        <p>
The purpose of the Shared Kernel is to reduce duplication, but still keep two separate
contexts. 
</p>
        <p>
  
</p>
        <p>
          <strong>Core Domain and Generic Subdomain</strong>
        </p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
          <strong>
            <font size="3">Last Chapter</font>
          </strong>
        </p>
        <p>
  
</p>
        <p>
Keep in mind some of the pitfalls of domain modeling:<br />
1) Stay hands-on. Modelers need to code.<br />
2) Focus on concrete scenarios. Abstract thinking has to be anchored in concrete cases.<br />
3) Don't try to apply DDD to everything. Draw a context map and decide on where you
will make a push for DDD and where you will not. And then don't worry about it outside
those boundaries.<br />
4) Experiment a lot and expect to make lots of mistakes. Modeling is a creative process. <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=8de2cc59-7159-4e28-a5c9-4fe776be0782" /></p>
      </body>
      <title>Domain Drive Design Quickly &amp;ndash; book review</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,8de2cc59-7159-4e28-a5c9-4fe776be0782.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,8de2cc59-7159-4e28-a5c9-4fe776be0782.aspx</link>
      <pubDate>Mon, 25 Jan 2010 21:54:21 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;(By Eric Evan)&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;Chapter 1 What Is Domain-Driven Design&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
When we begin a software project, we should focus on the domain it is operating in.
The entire purpose of the software is to enhance a specific domain. 
&lt;p&gt;
How can we make the software fit harmoniously with the domain? The best way to do
it is to make software a reflection of the domain.&lt;br&gt;
&lt;p&gt;
The model is our internal representation of the target domain, and it is very necessary
throughout the design and the development process.
&lt;/p&gt;
&lt;p&gt;
There are different approaches to software design. One is the waterfall design method.
This method involves a number of stages. The business experts put up a set of requirements
which are communicated to the business analysts. The analysts create a model based
on those requirements, and pass the results to the developers, who start coding based
on what they have received. It’s a one way flow of knowledge. While this has been
a traditional approach in software design, and has been used with a certain level
of success over the years, it has its flaws and limits. The main problem is that there
is no feedback from the analysts to the business experts or from the developers to
the analysts. Another approach is the Agile methodologies, such as Extreme Programming
(XP). These methodologies are a collective movement against the waterfall approach,
resulting from the difficulties of trying to come up with all the requirements upfront,
particularly in light of requirements change. It’s really hard to create a complete
model which covers all aspects of a domain upfront. It takes a lot of thinking, and
often you just cannot see all the issues involved from the beginning, nor can you
foresee some of the negative side effects or mistakes of your design. Another problem
Agile attempts to solve is the so called “analysis paralysis”, with team members so
afraid of making any design decisions that they make no progress at all. While Agile
advocates recognize the importance of design decision, they resist upfront design.
Instead they employ a great deal of implementation flexibility, and through iterative
development with continuous business stakeholder participation and a lot of refactoring,
the development team gets to learn more about the customer domain and can better produce
software that meets the customers needs. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The Agile methods have their own problems and limitations; they advocate simplicity,
but everybody has their own view of what that means. Also, continuous refactoring
done by developers without solid design principles will produce code that is hard
to understand or change. And while the waterfall approach may lead to over-engineering,
the fear of overengineering may lead to another fear: the fear of doing a deep, thoroughly
thought out design. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;font size="2"&gt;&lt;strong&gt;Chapter 2 The Ubiquitous Language&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
A core principle of domain-driven design is to use a language based on the model.
Since the model is the common ground, the place where the software meets the domain,
it is appropriate to use it as the building ground for this language. 
&lt;p&gt;
Building a language like that has a clear outcome: the model and the language are
strongly interconnected with one another. A change in the language should become a
change to the model. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;font size="2"&gt;&lt;strong&gt;Chapter 3 Model-Driven Design&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
A better approach is to closely relate domain modeling and design. The model should
be constructed with an eye open to the software and design considerations. Developers
should be included in the modeling process. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb_2.png" width="792" height="564"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb_3.png" width="735" height="420"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb_4.png" width="660" height="469"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Entities&lt;/strong&gt;: There is a category of objects which seem to have an identity,
which remains the same throughout the states of the software. For these objects it
is not the attributes which matter, but a thread of continuity and identity, which
spans the life of a system and can extend beyond it. Such objects are called Entities. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Value Objects&lt;/strong&gt;:&amp;nbsp; There are cases when we need to contain some
attributes of a domain element. We are not interested in which object it is, but what
attributes it has. An object that is used to describe certain aspects of a domain,
and which does not have identity, is named Value Object. 
&lt;p&gt;
It is highly recommended that value objects be immutable.&lt;br&gt;
One golden rule is: if Value Objects are shareable, they should be immutable. Value
Objects should be kept thin and simple. When a Value Object is needed by another party,
it can be simply passed by value, or a copy of it can be created and given. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Services&lt;/strong&gt;: 
&lt;p&gt;
we discover that some aspects of the domain are not easily mapped to objects.&amp;nbsp;
But there are some actions in the domain, some verbs, which do not seem to belong
to any object. They represent an important behavior of the domain, so they cannot
be neglected or simply incorporated into some of the Entities or Value Objects. When
such a behavior is recognized in the domain, the best practice is to declare it as
a Service. Such an object does not have an internal state, and its purpose is to simply
provide functionality for the domain. The assistance provided by a Service can be
a significant one, and a Service can group related functionality which serves the
Entities and the Value Objects. 
&lt;p&gt;
(For example, to transfer money from one account to another; should that function
be in the sending account or the receiving account? It feels just as misplaced in
either.) 
&lt;p&gt;
There are three characteristics of a Service:&lt;br&gt;
1. The operation performed by the Service refers to a domain concept which does not
naturally belong to an Entity or Value&lt;br&gt;
Object.&lt;br&gt;
2. The operation performed refers to other objects in the domain.&lt;br&gt;
3. The operation is stateless. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Modules&lt;/strong&gt;: it is necessary to organize the model into modules. Modules
are used as a method of organizing related concepts and tasks in order to reduce complexity. 
&lt;br&gt;
&lt;p&gt;
Another reason for using modules is related to code quality. It is widely accepted
that software code should have &lt;strong&gt;a high level of cohesion and a low level of
coupling&lt;/strong&gt;.&lt;br&gt;
&lt;p&gt;
Two of the most used are &lt;strong&gt;communicational cohesion and functional cohesion&lt;/strong&gt;. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Three patterns:&amp;nbsp; Aggregate is a domain pattern used to define object
ownership and boundaries. Factories and Repositories are two design patterns which
help us deal with object creation and storage.&lt;/strong&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
An &lt;strong&gt;Aggregate&lt;/strong&gt; is a group of associated objects which are considered
as one unit with regard to data changes. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The root is an Entity, and it is the only object accessible from outside. The root
can hold references to any of the aggregate objects, and the other objects can hold
references to each other, but an outside object can hold references only to the root
object. 
&lt;p&gt;
Cluster the Entities and Value Objects into Aggregates and define boundaries around
each. Choose one Entity to be the root of each Aggregate, and control all access to
the objects inside the boundary through the root. Allow external objects to hold references
to the root only. Transient references to internal members can be passed out for use
within a single operation only. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Factories&lt;/strong&gt; are used to encapsulate the knowledge necessary for object
creation, and they are especially useful to create Aggregates. When the root of the
Aggregate is created, all the objects contained by the Aggregate are created along
with it, and all the invariants are enforced.&lt;br&gt;
A Factory Method is an object method which contains and hides knowledge necessary
to create another object. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
There are times when a Factory is not needed, and a simple constructor is enough.
Use a constructor when:&lt;br&gt;
• The construction is not complicated.&lt;br&gt;
• The creation of an object does not involve the creation of others, and all the attributes
needed are passed via the constructor.&lt;br&gt;
• The client is interested in the implementation, perhaps wants to choose the Strategy
used.&lt;br&gt;
• The class is the type. There is no hierarchy involved, so no need to choose between
a list of concrete implementations. 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Therefore, use a &lt;strong&gt;Repository&lt;/strong&gt;, the purpose of which is to encapsulate
all the logic needed to obtain object references. 
&lt;p&gt;
The overall effect is that the domain model is decoupled from the need of storing
objects or their references, and accessing the&lt;br&gt;
underlying persistence infrastructure. Provide repositories only for Aggregate roots
that actually need direct access. Keep the client focused on the model, delegating
all object storage and access to the Repositories. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
There is a relationship between Factory and Repository. They are both patterns of
the model-driven design, and they both help us to manage the life cycle of domain
objects. While the Factory is concerned with the creation of objects, the Repository
takes care of already existing objects. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;Chapter 4 Refactoring Toward Deeper Insight&lt;/font&gt;&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/strong&gt;&amp;nbsp; 
&lt;p&gt;
One of the first things we are taught about modeling is to read the business specifications
and look for nouns and verbs. The nouns are converted to classes, while the verbs
become methods. This is a simplification, and will lead to a &lt;strong&gt;shallow&lt;/strong&gt; model. 
&lt;p&gt;
We start with a coarse, shallow model. Then we refine it and the design based on deeper
knowledge about the domain, on a better understanding of the concerns. We add new
concepts and abstractions to it. The design is then refactored. Each refinement adds
more clarity to the design. This creates in turn the premises for a Breakthrough. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
To reach a Breakthrough, we need to make the implicit concepts explicit.&lt;br&gt;
&lt;p&gt;
The first way to discover implicit concepts is to listen to the language.&lt;br&gt;
&lt;p&gt;
Try to see if there is a missing concept. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Another obvious way of digging out model concepts is to use domain literature. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
There are other concepts which are very useful when made explicit: Constraint, Process
and Specification.&lt;br&gt;
&lt;p&gt;
Placing the Constraint into a separate method has the advantage of making it explicit. 
&lt;br&gt;
Processes are usually expressed in code with procedures.&lt;br&gt;
Simply said, a Specification is used to test an object to see if it satisfies a certain
criteria. The domain layer contains business rules which are applied to Entities and
Value Objects. Those rules are usually incorporated into the objects they apply to.
When rule is not a simple method and spans many entities and value objects,&amp;nbsp;
the rule should be encapsulated into an object of its own, which becomes the Specification
of the Customer, and should be kept in the domain layer. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;Chapter 5 Preserving Model Integrity&lt;/font&gt;&lt;/strong&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
This chapter is about large projects which require the combined efforts of multiple
teams. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Instead of trying to keep one big model that will fall apart later, we should consciously
divide it into several models. 
&lt;p&gt;
Each model should have a clearly delimited border, and the relationships between models
should be defined with precision. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/DomainDriveDesign_EE07/image_thumb.png" width="731" height="381"&gt;&lt;/a&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
A model should be small enough to be assigned to one team. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Bounded Context&lt;/strong&gt;: The main idea is to define the scope of a model,
to draw up the boundaries of its context, then do the most possible to keep the model
unified.&lt;br&gt;
Explicitly set boundaries in terms of team organization, usage within specific parts
of the application, and physical manifestations such as code bases and database schemas.
Keep the model strictly consistent within these bounds, but don’t be distracted or
confused by issues outside. 
&lt;p&gt;
A Bounded Context is not a Module. A Bounded Context provides the logical frame inside
of which the model evolves. Modules are used to organize the elements of a model,
so Bounded Context encompasses the Module. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
A &lt;strong&gt;Context Map&lt;/strong&gt; is a document which outlines the different Bounded
Contexts and the relationships between them. What it is important is that everyone
working on the project shares and understands it. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
A common practice is to define the contexts, then create modules for each context,
and use a naming convention to indicate the context each module belongs to. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
The purpose of the Shared Kernel is to reduce duplication, but still keep two separate
contexts. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;Core Domain and Generic Subdomain&lt;/strong&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp; 
&lt;p&gt;
&lt;strong&gt;&lt;font size="3"&gt;Last Chapter&lt;/font&gt;&lt;/strong&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Keep in mind some of the pitfalls of domain modeling:&lt;br&gt;
1) Stay hands-on. Modelers need to code.&lt;br&gt;
2) Focus on concrete scenarios. Abstract thinking has to be anchored in concrete cases.&lt;br&gt;
3) Don't try to apply DDD to everything. Draw a context map and decide on where you
will make a push for DDD and where you will not. And then don't worry about it outside
those boundaries.&lt;br&gt;
4) Experiment a lot and expect to make lots of mistakes. Modeling is a creative process. &lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=8de2cc59-7159-4e28-a5c9-4fe776be0782" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,8de2cc59-7159-4e28-a5c9-4fe776be0782.aspx</comments>
      <category>Design;DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=21db3bdc-184e-4548-afe7-5d7cb366dd4b</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,21db3bdc-184e-4548-afe7-5d7cb366dd4b.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,21db3bdc-184e-4548-afe7-5d7cb366dd4b.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=21db3bdc-184e-4548-afe7-5d7cb366dd4b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://referencesource.microsoft.com/serversetup.aspx" href="http://referencesource.microsoft.com/serversetup.aspx">http://referencesource.microsoft.com/serversetup.aspx</a>
        </p>
        <h3>Configuring Visual Studio for Debugging
</h3>
        <h4>Set Up Visual Studio 2008:
</h4>
        <p>
a. Install and set up Visual Studio 2008 including any updates. 
</p>
        <h4>Set Up the Symbols Path:
</h4>
        <p>
a. Launch Visual Studio 2008.<br />
b. From the Tools menu, choose Options.<br />
c. In the Options dialog box, open the Debugging node and select General 
<br />
        a. Clear 'Enable Just My Code (Managed
only)'<br />
        b. Check 'Enable source server support' 
</p>
        <p>
          <img src="http://referencesource.microsoft.com/images/image_thumb_11.png" />
        </p>
        <p>
d. Select Symbols under Debugging.<br />
e. In the Symbol File Locations box, add the following location:<br />
   http://referencesource.microsoft.com/symbols 
</p>
        <p>
          <img src="http://referencesource.microsoft.com/images/image_thumb_2.png" />
        </p>
        <p>
   Note: To add the Symbols path Click folder icon. 
<br />
f. Enter in text box under 'Cache symbols from symbol servers to this directory:'
C:\Symbols\RSCC:<br />
   Note : If C:\Symbols is already in use then you can chose another folder
name. The folder name must be input into the 
<br />
   text box 
<br />
g. Click OK. 
</p>
        <h4>Debugging your Application
</h4>
        <p>
a. Open your application code solution and build the solution.<br />
b. Set a break point in the code.<br />
c. Start debugging (press F5).<br />
d. EULA pops up, click Accept.<br />
e. Source code will be downloaded. <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=21db3bdc-184e-4548-afe7-5d7cb366dd4b" /></p>
      </body>
      <title>Configuring Visual Studio for Debugging</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,21db3bdc-184e-4548-afe7-5d7cb366dd4b.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,21db3bdc-184e-4548-afe7-5d7cb366dd4b.aspx</link>
      <pubDate>Fri, 15 Jan 2010 21:14:56 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://referencesource.microsoft.com/serversetup.aspx" href="http://referencesource.microsoft.com/serversetup.aspx"&gt;http://referencesource.microsoft.com/serversetup.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Configuring Visual Studio for Debugging
&lt;/h3&gt;
&lt;h4&gt;Set Up Visual Studio 2008:
&lt;/h4&gt;
&lt;p&gt;
a. Install and set up Visual Studio 2008 including any updates. 
&lt;h4&gt;Set Up the Symbols Path:
&lt;/h4&gt;
&lt;p&gt;
a. Launch Visual Studio 2008.&lt;br&gt;
b. From the Tools menu, choose Options.&lt;br&gt;
c. In the Options dialog box, open the Debugging node and select General 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a. Clear 'Enable Just My Code (Managed
only)'&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b. Check 'Enable source server support' 
&lt;p&gt;
&lt;img src="http://referencesource.microsoft.com/images/image_thumb_11.png"&gt; 
&lt;p&gt;
d. Select Symbols under Debugging.&lt;br&gt;
e. In the Symbol File Locations box, add the following location:&lt;br&gt;
&amp;nbsp;&amp;nbsp; http://referencesource.microsoft.com/symbols 
&lt;p&gt;
&lt;img src="http://referencesource.microsoft.com/images/image_thumb_2.png"&gt; 
&lt;p&gt;
&amp;nbsp;&amp;nbsp; Note: To add the Symbols path Click folder icon. 
&lt;br&gt;
f. Enter in text box under 'Cache symbols from symbol servers to this directory:'
C:\Symbols\RSCC:&lt;br&gt;
&amp;nbsp;&amp;nbsp; Note : If C:\Symbols is already in use then you can chose another folder
name. The folder name must be input into the 
&lt;br&gt;
&amp;nbsp;&amp;nbsp; text box 
&lt;br&gt;
g. Click OK. 
&lt;h4&gt;Debugging your Application
&lt;/h4&gt;
&lt;p&gt;
a. Open your application code solution and build the solution.&lt;br&gt;
b. Set a break point in the code.&lt;br&gt;
c. Start debugging (press F5).&lt;br&gt;
d. EULA pops up, click Accept.&lt;br&gt;
e. Source code will be downloaded. &lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=21db3bdc-184e-4548-afe7-5d7cb366dd4b" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,21db3bdc-184e-4548-afe7-5d7cb366dd4b.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=4e773956-f31d-487e-8783-d2e8320e61da</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,4e773956-f31d-487e-8783-d2e8320e61da.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,4e773956-f31d-487e-8783-d2e8320e61da.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4e773956-f31d-487e-8783-d2e8320e61da</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Model-View Architecture 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb.png" width="598" height="167" />
          </a>
        </p>
        <p>
Three-Tie Architecture
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_1.png" width="620" height="157" />
          </a>
        </p>
        <p>
Model-View-Controller Architecture
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_2.png" width="617" height="162" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_4.png" width="634" height="190" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_5.png" width="643" height="395" />
          </a>
        </p>
        <p>
 
</p>
        <p>
The preceding test is a unit test, because it tests just one isolated component: AdminController.<br />
It doesn’t rely on any real implementation of IMembersRepository, and so it doesn’t
need to<br />
access any database. 
</p>
        <p>
  
</p>
        <p>
When you deliberately chain together a series of components and test them together,<br />
that’s an integration test. 
</p>
        <p>
 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_7.png" width="663" height="119" />
          </a> 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_14.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_6.png" width="663" height="331" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_18.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_8.png" width="674" height="227" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_20.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_3.png" width="601" height="822" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_22.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_9.png" width="679" height="198" />
          </a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=4e773956-f31d-487e-8783-d2e8320e61da" />
      </body>
      <title>Professional ASP.Net MVC Framework - part1</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,4e773956-f31d-487e-8783-d2e8320e61da.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,4e773956-f31d-487e-8783-d2e8320e61da.aspx</link>
      <pubDate>Thu, 14 Jan 2010 22:35:20 GMT</pubDate>
      <description>&lt;p&gt;
Model-View Architecture 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb.png" width="598" height="167"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Three-Tie Architecture
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_1.png" width="620" height="157"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Model-View-Controller Architecture
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_2.png" width="617" height="162"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_4.png" width="634" height="190"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_5.png" width="643" height="395"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The preceding test is a unit test, because it tests just one isolated component: AdminController.&lt;br&gt;
It doesn’t rely on any real implementation of IMembersRepository, and so it doesn’t
need to&lt;br&gt;
access any database. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
When you deliberately chain together a series of components and test them together,&lt;br&gt;
that’s an integration test. 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_7.png" width="663" height="119"&gt;&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_6.png" width="663" height="331"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_8.png" width="674" height="227"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_20.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_3.png" width="601" height="822"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_22.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ProfessionalASP.NetMVCFrameworkpart1_F790/image_thumb_9.png" width="679" height="198"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=4e773956-f31d-487e-8783-d2e8320e61da" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,4e773956-f31d-487e-8783-d2e8320e61da.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=314c1a07-53ce-4625-a1c1-2790e3366024</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,314c1a07-53ce-4625-a1c1-2790e3366024.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,314c1a07-53ce-4625-a1c1-2790e3366024.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=314c1a07-53ce-4625-a1c1-2790e3366024</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.asp.net/learn/mvc/tutorial-08-cs.aspx" href="http://www.asp.net/learn/mvc/tutorial-08-cs.aspx">http://www.asp.net/learn/mvc/tutorial-08-cs.aspx</a>
        </p>
        <p>
          <a title="http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/" href="http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/">http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/</a>
        </p>
        <p>
Instead of using the registermvc.wcf script, you can add a new extension to IIS that
is mapped to the ASP.NET framework by hand. When adding a new extension yourself,
make sure that the checkbox labeled <b>Verify that file exists</b> is <font size="6">not</font> checked.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=314c1a07-53ce-4625-a1c1-2790e3366024" />
      </body>
      <title>How to deploy ASP.Net MVC to IIS6</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,314c1a07-53ce-4625-a1c1-2790e3366024.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,314c1a07-53ce-4625-a1c1-2790e3366024.aspx</link>
      <pubDate>Thu, 29 Oct 2009 15:52:05 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="http://www.asp.net/learn/mvc/tutorial-08-cs.aspx" href="http://www.asp.net/learn/mvc/tutorial-08-cs.aspx"&gt;http://www.asp.net/learn/mvc/tutorial-08-cs.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/" href="http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/"&gt;http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Instead of using the registermvc.wcf script, you can add a new extension to IIS that
is mapped to the ASP.NET framework by hand. When adding a new extension yourself,
make sure that the checkbox labeled &lt;b&gt;Verify that file exists&lt;/b&gt; is &lt;font size="6"&gt;not&lt;/font&gt; checked.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=314c1a07-53ce-4625-a1c1-2790e3366024" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,314c1a07-53ce-4625-a1c1-2790e3366024.aspx</comments>
      <category>DotNet;DotNet / ASP</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=e8df4b61-6599-4aae-adde-5b3188abea41</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,e8df4b61-6599-4aae-adde-5b3188abea41.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,e8df4b61-6599-4aae-adde-5b3188abea41.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e8df4b61-6599-4aae-adde-5b3188abea41</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The <tt>BackgroundWorker</tt> class is built on top of <tt>ThreadPool</tt> and adds
many features for interthread communication.
</p>
        <p>
          <a name="iddle1111">
          </a>
          <a name="iddle1201">
          </a>
          <a name="iddle1236">
          </a>
          <a name="iddle1248">
          </a>
          <a name="iddle1745">
          </a>
          <a name="iddle1861">
          </a>The
single most important issue you must deal with is exceptions in your <tt>WaitCallback</tt>,
the method that does the work in the background thread. If any exceptions are thrown
from that method, the system will terminate your application. It doesn't simply terminate
that one background thread; it terminates the entire application. This behavior is
consistent with other background thread API methods, but the difference is that <tt>QueueUserWorkItem</tt> doesn't
have any built-in capability to handle reporting errors. 
</p>
        <p>
In addition, <tt>QueueUserWorkItem</tt> does not give you any built-in methods to
communicate between the background threads and the foreground thread. It doesn't provide
any built-in means for you to detect completion, track progress, pause tasks, or cancel
tasks. When you need those capabilities, you can turn to the <tt>BackgroundWorker</tt> component,
which is built on top of the <tt>QueueUserWorkItem</tt> functionality. 
</p>
        <p>
  
</p>
        <p>
For most common synchronization problems, examine the <tt>Interlocked</tt> class to
see whether you can use it to provide the capabilities you need. With many single
operations, you can. Otherwise, your first choice is the <tt>lock()</tt> statement.
Look beyond those only when you need special-purpose locking capability. 
</p>
        <p>
  
</p>
        <p>
Two of the most widely used locking techniques are just plain wrong when seen from
that viewpoint. <tt>lock(this)</tt> and <tt>lock(TypeOf(MyType))</tt> have the nasty
effect of creating your lock object based on a publicly accessible instance. 
</p>
        <p>
  
</p>
        <p>
When you decide what to lock, pick a private field that's not visible to any callers.
Do not lock a publicly visible object. Locking publicly visible <a name="iddle1526"></a><a name="iddle1533"></a><a name="iddle1591"></a><a name="iddle1842"></a><a name="iddle1873"></a>objects
requires that all developers always and forever follow the same practice, and it enables
client code to easily introduce deadlock issues. 
</p>
        <p>
 
</p>
        <p>
No matter how it happens, the pattern is similar. Your class acquires a lock. Then,
while still in the synchronized section, it invokes a method that calls code beyond
your control. That client code is an open-ended set of code that may eventually trace
back into your class, even on another thread. You can't do anything to prevent that
open-ended set of code from doing something that might be evil. So instead, you must
prevent the situation: Don't call unknown code from inside locked sections of your
code.
</p>
        <p>
Let's summarize what you've learned about <tt>InvokeRequired</tt>. Once your controls
are created, <tt>InvokeRequired</tt> is reasonably fast and always safe. However,
if the target control has not been created, <tt>InvokeRequired</tt> can take much
longer, and if none of the controls has been created, <tt>InvokeRequired</tt> takes
a long time to give you an answer that's probably not even correct. Even though <tt>Control.InvokeRequired</tt> can
be a bit expensive, it's still quite a bit cheaper than a call to <tt>Control.Invoke</tt> when
it's not necessary. In WPF, some of the edge cases have been optimized and work better
than they do in the Windows Forms implementation.
</p>
        <p>
          <tt>Invoke</tt> and <tt>InvokeRequired</tt> do quite a bit of work on your behalf.
All this work is required because Windows Forms controls are built on the single-threaded
apartment model. That legacy behavior continues under the new WPF libraries. Underneath
all the new .NET Framework code, the Win32 API and window messages are still lurking.
That message passing and thread marshaling can lead to unexpected behavior. You need
to understand what those methods do and work with their behavior.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=e8df4b61-6599-4aae-adde-5b3188abea41" />
      </body>
      <title>Effective c# part2</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,e8df4b61-6599-4aae-adde-5b3188abea41.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,e8df4b61-6599-4aae-adde-5b3188abea41.aspx</link>
      <pubDate>Mon, 19 Oct 2009 21:30:23 GMT</pubDate>
      <description>&lt;p&gt;
The &lt;tt&gt;BackgroundWorker&lt;/tt&gt; class is built on top of &lt;tt&gt;ThreadPool&lt;/tt&gt; and adds
many features for interthread communication.
&lt;/p&gt;
&lt;p&gt;
&lt;a name="iddle1111"&gt;&lt;/a&gt;&lt;a name="iddle1201"&gt;&lt;/a&gt;&lt;a name="iddle1236"&gt;&lt;/a&gt;&lt;a name="iddle1248"&gt;&lt;/a&gt;&lt;a name="iddle1745"&gt;&lt;/a&gt;&lt;a name="iddle1861"&gt;&lt;/a&gt;The
single most important issue you must deal with is exceptions in your &lt;tt&gt;WaitCallback&lt;/tt&gt;,
the method that does the work in the background thread. If any exceptions are thrown
from that method, the system will terminate your application. It doesn't simply terminate
that one background thread; it terminates the entire application. This behavior is
consistent with other background thread API methods, but the difference is that &lt;tt&gt;QueueUserWorkItem&lt;/tt&gt; doesn't
have any built-in capability to handle reporting errors. 
&lt;p&gt;
In addition, &lt;tt&gt;QueueUserWorkItem&lt;/tt&gt; does not give you any built-in methods to
communicate between the background threads and the foreground thread. It doesn't provide
any built-in means for you to detect completion, track progress, pause tasks, or cancel
tasks. When you need those capabilities, you can turn to the &lt;tt&gt;BackgroundWorker&lt;/tt&gt; component,
which is built on top of the &lt;tt&gt;QueueUserWorkItem&lt;/tt&gt; functionality. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
For most common synchronization problems, examine the &lt;tt&gt;Interlocked&lt;/tt&gt; class to
see whether you can use it to provide the capabilities you need. With many single
operations, you can. Otherwise, your first choice is the &lt;tt&gt;lock()&lt;/tt&gt; statement.
Look beyond those only when you need special-purpose locking capability. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Two of the most widely used locking techniques are just plain wrong when seen from
that viewpoint. &lt;tt&gt;lock(this)&lt;/tt&gt; and &lt;tt&gt;lock(TypeOf(MyType))&lt;/tt&gt; have the nasty
effect of creating your lock object based on a publicly accessible instance. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
When you decide what to lock, pick a private field that's not visible to any callers.
Do not lock a publicly visible object. Locking publicly visible &lt;a name="iddle1526"&gt;&lt;/a&gt;&lt;a name="iddle1533"&gt;&lt;/a&gt;&lt;a name="iddle1591"&gt;&lt;/a&gt;&lt;a name="iddle1842"&gt;&lt;/a&gt;&lt;a name="iddle1873"&gt;&lt;/a&gt;objects
requires that all developers always and forever follow the same practice, and it enables
client code to easily introduce deadlock issues. 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
No matter how it happens, the pattern is similar. Your class acquires a lock. Then,
while still in the synchronized section, it invokes a method that calls code beyond
your control. That client code is an open-ended set of code that may eventually trace
back into your class, even on another thread. You can't do anything to prevent that
open-ended set of code from doing something that might be evil. So instead, you must
prevent the situation: Don't call unknown code from inside locked sections of your
code.
&lt;/p&gt;
&lt;p&gt;
Let's summarize what you've learned about &lt;tt&gt;InvokeRequired&lt;/tt&gt;. Once your controls
are created, &lt;tt&gt;InvokeRequired&lt;/tt&gt; is reasonably fast and always safe. However,
if the target control has not been created, &lt;tt&gt;InvokeRequired&lt;/tt&gt; can take much
longer, and if none of the controls has been created, &lt;tt&gt;InvokeRequired&lt;/tt&gt; takes
a long time to give you an answer that's probably not even correct. Even though &lt;tt&gt;Control.InvokeRequired&lt;/tt&gt; can
be a bit expensive, it's still quite a bit cheaper than a call to &lt;tt&gt;Control.Invoke&lt;/tt&gt; when
it's not necessary. In WPF, some of the edge cases have been optimized and work better
than they do in the Windows Forms implementation.
&lt;/p&gt;
&lt;p&gt;
&lt;tt&gt;Invoke&lt;/tt&gt; and &lt;tt&gt;InvokeRequired&lt;/tt&gt; do quite a bit of work on your behalf.
All this work is required because Windows Forms controls are built on the single-threaded
apartment model. That legacy behavior continues under the new WPF libraries. Underneath
all the new .NET Framework code, the Win32 API and window messages are still lurking.
That message passing and thread marshaling can lead to unexpected behavior. You need
to understand what those methods do and work with their behavior.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=e8df4b61-6599-4aae-adde-5b3188abea41" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,e8df4b61-6599-4aae-adde-5b3188abea41.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=d91135ac-13e9-45e7-9601-09c4a6b7a6c2</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,d91135ac-13e9-45e7-9601-09c4a6b7a6c2.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,d91135ac-13e9-45e7-9601-09c4a6b7a6c2.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d91135ac-13e9-45e7-9601-09c4a6b7a6c2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="4">Chapter 1 : Working with Generics.</font>
        </p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">class</span> EmployeeComparer
: EqualityComparer&lt;Employee&gt;</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">override</span>
            <span class="kwrd">bool</span> Equals(Employee
x, Employee y)</pre>
          <pre>
            <span class="lnum"> 4: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">return</span> EqualityComparer&lt;Employee&gt;.Default.Equals(x,
y);</pre>
          <pre>
            <span class="lnum"> 6: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span> </pre>
          <pre>
            <span class="lnum"> 8: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">override</span>
            <span class="kwrd">int</span> GetHashCode(Employee
obj)</pre>
          <pre class="alt">
            <span class="lnum"> 9: </span> {</pre>
          <pre>
            <span class="lnum"> 10: </span>
            <span class="kwrd">return</span> EqualityComparer&lt;Employee&gt;.Default.</pre>
          <pre class="alt">
            <span class="lnum"> 11: </span> GetHashCode(obj);</pre>
          <pre>
            <span class="lnum"> 12: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 13: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
The <tt>Default</tt> property examines the type argument, <tt>T</tt>. If the type
implements <tt>IEquatable&lt;T&gt;</tt>, then <tt>Default</tt> returns an <tt>IEqualityComparer&lt;T&gt;</tt> that
uses the generic interface. If not, <tt>Default</tt> returns an <tt>IEqualityComparer&lt;T&gt;</tt> that
uses the <tt>System.Object</tt> virtual methods <tt>Equals()</tt> and <tt>GetHashCode()</tt>.
In this way, <tt>EqualityComparer&lt;T&gt;</tt> guarantees the best implementation
for you. 
</p>
        <p>
  
</p>
        <p>
 
</p>
        <pre>
          <font size="2">
            <strong>
              <u>public delegate void Action&lt;T&gt;(T obj);</u>
            </strong>
          </font>
          <br />
        </pre>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">void</span> EnumerateAll&lt;T&gt;(<span class="kwrd">this</span> IEnumerable&lt;T&gt;</pre>
          <pre>
            <span class="lnum"> 2: </span>theCollection, Action&lt;T&gt; doIt)</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>{</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">foreach</span> (T thing <span class="kwrd">in</span> theCollection)</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> doIt(thing);</pre>
          <pre>
            <span class="lnum"> 6: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
          <font size="2">
            <strong>delegate bool Predicate&lt;T&gt;(T obj)</strong>
          </font>
        </p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span> IEnumerable&lt;T&gt;
Test&lt;T&gt; (IEnumerable&lt;T&gt; theCollection,</pre>
          <pre>
            <span class="lnum"> 2: </span>Predicate&lt;T&gt; test)</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>{</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">foreach</span> (T source <span class="kwrd">in</span> theCollection)</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">if</span> ( test(
source ) )</pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">yield</span>
            <span class="kwrd">return</span> source;</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
        </p>
        <pre>
          <font size="2">
            <strong>public delegate void EventHandler&lt;TEventArgs&gt;( object
sender, TEventArgs args) where TEventArgs: EventArgs</strong>
          </font>
        </pre>
        <strong>
          <pre>
            <br />
            <font size="2">Now you can define a event like this<br /></font>
          </pre>
        </strong>
        <font size="2">public event EventHandler&lt;MyEventArgs&gt; OnRaiseMyEvent;</font>
        <pre>
          <font size="2">Performance of boxing of unboxing<br /></font>1. A new object must be allocated on the managed heap.<br />
2. The value of the stack-based data must be transferred into that memory location.<br />
3. When unboxed, the value stored on the heap-based object must be transferred back
to the stack.<br />
4. The now unused object on the heap will (eventually) be garbage collected.</pre>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span> T
FirstOrDefault&lt;T&gt;(<span class="kwrd">this</span> IEnumerable&lt;T&gt; sequence,</pre>
          <pre>
            <span class="lnum"> 2: </span> Predicate&lt;T&gt; test)</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>{</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">foreach</span> (T <span class="kwrd">value</span><span class="kwrd">in</span> sequence)</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">if</span> (test(<span class="kwrd">value</span>))</pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">value</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span> </pre>
          <pre>
            <span class="lnum"> 8: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">default</span>(T);</pre>
          <pre class="alt">
            <span class="lnum"> 9: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <div class="csharpcode">
          <pre class="alt">
            <p>
              <span class="lnum">
              </span> 
</p>
            <p>
              <span class="lnum">
              </span> 
</p>
            <p>
              <span class="lnum"> 1: </span>
              <span class="kwrd">public</span>
              <span class="kwrd">delegate</span> T
FactoryFunc&lt;T&gt;();
</p>
          </pre>
          <pre>
            <span class="lnum"> 2: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span> T
Factory&lt;T&gt;(FactoryFunc&lt;T&gt; makeANewT)</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>
            <span class="kwrd">where</span> T
: <span class="kwrd">new</span>()</pre>
          <pre>
            <span class="lnum"> 4: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> T rVal = makeANewT();</pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">if</span> (rVal == <span class="kwrd">null</span>)</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">new</span> T();</pre>
          <pre>
            <span class="lnum"> 8: </span>
            <span class="kwrd">else</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 9: </span>
            <span class="kwrd">return</span> rVal;</pre>
          <pre>
            <span class="lnum"> 10: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <pre> Ensure your generic classes support disposable type parameters<br /></pre>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">void</span> GetThingsDone()</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span> T driver = <span class="kwrd">new</span> T();</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">using</span> (driver <span class="kwrd">as</span> IDisposable)</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> {</pre>
          <pre>
            <span class="lnum"> 6: </span> driver.DoWork();</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span> }</pre>
          <pre>
            <span class="lnum"> 8: </span>}</pre>
          <pre> </pre>
          <pre>If drive is a property member in the generic class, you have to implement IDisposable interface. So better to</pre>
          <pre>take it out from generic class.<br /></pre>
          <div class="csharpcode">
            <pre class="alt">
              <span class="lnum"> 1: </span>
              <span class="kwrd">public</span>
              <span class="kwrd">class</span> EngineDriver&lt;T&gt; <span class="kwrd">where</span> T
: IEngine</pre>
            <pre>
              <span class="lnum"> 2: </span>{</pre>
            <pre class="alt">
              <span class="lnum"> 3: </span>
              <span class="kwrd">private</span> T
driver;</pre>
            <pre>
              <span class="lnum"> 4: </span>
              <span class="kwrd">public</span> EngineDriver(T
driver)</pre>
            <pre class="alt">
              <span class="lnum"> 5: </span> {</pre>
            <pre>
              <span class="lnum"> 6: </span>
              <span class="kwrd">this</span>.driver = driver;</pre>
            <pre class="alt">
              <span class="lnum"> 7: </span> }</pre>
            <pre>
              <span class="lnum"> 8: </span> </pre>
            <pre class="alt">
              <span class="lnum"> 9: </span>
              <span class="kwrd">public</span>
              <span class="kwrd">void</span> GetThingsDone()</pre>
            <pre>
              <span class="lnum"> 10: </span> {</pre>
            <pre class="alt">
              <span class="lnum"> 11: </span> driver.DoWork();</pre>
            <pre>
              <span class="lnum"> 12: </span> }</pre>
            <pre class="alt">
              <span class="lnum"> 13: </span>}</pre>
          </div>
          <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
        </p>
        <p>
        </p>
        <p>
          <strong>
            <font size="2">Use Delegates to define method constrains on Type Parameters</font>
          </strong>
          <br />
When it's unwieldy to use an interface to define a constraint, you can define a method
signature and a delegate type that suits your needs. Then you add an instance of that
delegate to the list of the parameters of the generic method. The developers using
your class can use a lambda expression to define that method, writing much less code,
in a much clearer fashion. Developers using your class need to create the lambda expression
that defines the method functionality they need. There's no extra code to support
the syntax of interface-based constraints.
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">class</span> Example</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span> T
Add&lt;T&gt;(T left, T right,</pre>
          <pre>
            <span class="lnum"> 4: </span> Func&lt;T, T, T&gt; AddFunc)</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> {</pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">return</span> AddFunc(left,
right);</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span> }</pre>
          <pre>
            <span class="lnum"> 8: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
In the general case, any method your generic class needs to call can be replaced by
a specific delegate.
</p>
        <p>
It's not a good idea to create generic specializations for base classes when you intend
to support the class and all its descendents.<br />
(That is to say: don’t create a same name generic method in a class as the names in
base classes or derivative classes))
</p>
        <p>
          <strong>If a type needs type-level data members, especially data members involving
the type parameter, make it a generic class. Otherwise, use generic methods.<br /></strong>Obviously, not every generic algorithm is suited for generic methods instead
of a generic class. Some simple guidelines can help you determine which to use. In
two cases you must make a generic class: The first occurs when your class stores a
value of one of the <tt>Type</tt> parameters as part of its internal state. (Collections
are an obvious example.) The second occurs when your class implements a generic interface.
Except for those two cases, you can usually create a nongeneric class and use generic
methods. You'll end up with more granularity in your options for updating the algorithms
in the future.
</p>
        <p>
One common problem for many developers is how to create a method signature for methods
that logically return more than one item. Many developers turn to <tt>ref</tt> or <tt>out</tt> parameters
in those cases. But it's better to define generic tuples that can return multiple
discrete values. A tuple is nothing more than a composite with n elements.<br /></p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">struct</span> Tuple&lt;T1,
T2&gt; : IEquatable&lt;Tuple&lt;T1, T2&gt;&gt;</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">readonly</span> T1
first;</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">public</span> T1 First</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> {</pre>
          <pre>
            <span class="lnum"> 6: </span> get { <span class="kwrd">return</span> first;
}</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span> }</pre>
          <pre>
            <span class="lnum"> 8: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 9: </span>
            <span class="kwrd">private</span>
            <span class="kwrd">readonly</span> T2
second;</pre>
          <pre>
            <span class="lnum"> 10: </span>
            <span class="kwrd">public</span> T2 Second</pre>
          <pre class="alt">
            <span class="lnum"> 11: </span> {</pre>
          <pre>
            <span class="lnum"> 12: </span> get { <span class="kwrd">return</span> second;
}</pre>
          <pre class="alt">
            <span class="lnum"> 13: </span> }</pre>
          <pre>
            <span class="lnum"> 14: </span> </pre>
          <pre class="alt">
            <span class="lnum"> 15: </span>
            <span class="kwrd">public</span> Tuple(T1
f, T2 s)</pre>
          <pre>
            <span class="lnum"> 16: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 17: </span> first = f;</pre>
          <pre>
            <span class="lnum"> 18: </span> second = s;</pre>
          <pre class="alt">
            <span class="lnum"> 19: </span> }</pre>
          <pre>
            <span class="lnum"> 20: </span>
            <span class="rem">// Implementation of IEquatable&lt;Tuple&lt;T1,
T2&gt;&gt; elided</span>
          </pre>
          <pre class="alt">
            <span class="lnum"> 21: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
  
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span> Tuple&lt;<span class="kwrd">string</span>, <span class="kwrd">decimal</span>&gt;
FindTempForNearestCity</pre>
          <pre>
            <span class="lnum"> 2: </span> (<span class="kwrd">string</span> soughtCity)</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>{</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">string</span> city = <span class="str">"algorithmElided"</span>;</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">decimal</span> temp
= <span class="kwrd">decimal</span>.MinValue; <span class="rem">// really cold.</span></pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">return</span>
            <span class="kwrd">new</span> Tuple&lt;<span class="kwrd">string</span>, <span class="kwrd">decimal</span>&gt;(city,
temp);</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>}</pre>
        </div>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=d91135ac-13e9-45e7-9601-09c4a6b7a6c2" />
      </body>
      <title>Effective c# part1</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,d91135ac-13e9-45e7-9601-09c4a6b7a6c2.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,d91135ac-13e9-45e7-9601-09c4a6b7a6c2.aspx</link>
      <pubDate>Thu, 15 Oct 2009 21:31:11 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="4"&gt;Chapter 1 : Working with Generics.&lt;/font&gt;
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EmployeeComparer
: EqualityComparer&amp;lt;Employee&amp;gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Equals(Employee
x, Employee y)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; EqualityComparer&amp;lt;Employee&amp;gt;.Default.Equals(x,
y);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; GetHashCode(Employee
obj)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; EqualityComparer&amp;lt;Employee&amp;gt;.Default.&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; GetHashCode(obj);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The &lt;tt&gt;Default&lt;/tt&gt; property examines the type argument, &lt;tt&gt;T&lt;/tt&gt;. If the type
implements &lt;tt&gt;IEquatable&amp;lt;T&amp;gt;&lt;/tt&gt;, then &lt;tt&gt;Default&lt;/tt&gt; returns an &lt;tt&gt;IEqualityComparer&amp;lt;T&amp;gt;&lt;/tt&gt; that
uses the generic interface. If not, &lt;tt&gt;Default&lt;/tt&gt; returns an &lt;tt&gt;IEqualityComparer&amp;lt;T&amp;gt;&lt;/tt&gt; that
uses the &lt;tt&gt;System.Object&lt;/tt&gt; virtual methods &lt;tt&gt;Equals()&lt;/tt&gt; and &lt;tt&gt;GetHashCode()&lt;/tt&gt;.
In this way, &lt;tt&gt;EqualityComparer&amp;lt;T&amp;gt;&lt;/tt&gt; guarantees the best implementation
for you. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
&amp;nbsp;&lt;pre&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;u&gt;public delegate void Action&amp;lt;T&amp;gt;(T obj);&lt;/u&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;br&gt;
&lt;/pre&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; EnumerateAll&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;theCollection, Action&amp;lt;T&amp;gt; doIt)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (T thing &lt;span class="kwrd"&gt;in&lt;/span&gt; theCollection)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; doIt(thing);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;strong&gt;delegate bool Predicate&amp;lt;T&amp;gt;(T obj)&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
Test&amp;lt;T&amp;gt; (IEnumerable&amp;lt;T&amp;gt; theCollection,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;Predicate&amp;lt;T&amp;gt; test)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (T source &lt;span class="kwrd"&gt;in&lt;/span&gt; theCollection)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; ( test(
source ) )&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; source;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;font size="2"&gt;&lt;strong&gt;public delegate void EventHandler&amp;lt;TEventArgs&amp;gt;( object
sender, TEventArgs args) where TEventArgs: EventArgs&lt;/strong&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;strong&gt;&lt;pre&gt;
&lt;br&gt;
&lt;font size="2"&gt;Now you can define a event like this&lt;br&gt;
&lt;/font&gt;
&lt;/strong&gt;&lt;font size="2"&gt;public event EventHandler&amp;lt;MyEventArgs&amp;gt; OnRaiseMyEvent;&lt;/font&gt;&gt;
&lt;pre&gt;&lt;font size="2"&gt;Performance of boxing of unboxing&lt;br&gt;
&lt;/font&gt;1. A new object must be allocated on the managed heap.&lt;br&gt;
2. The value of the stack-based data must be transferred into that memory location.&lt;br&gt;
3. When unboxed, the value stored on the heap-based object must be transferred back
to the stack.&lt;br&gt;
4. The now unused object on the heap will (eventually) be garbage collected.&lt;/pre&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T
FirstOrDefault&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt; sequence,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; Predicate&amp;lt;T&amp;gt; test)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (T &lt;span class="kwrd"&gt;value&lt;/span&gt; &lt;span class="kwrd"&gt;in&lt;/span&gt; sequence)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (test(&lt;span class="kwrd"&gt;value&lt;/span&gt;))&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;default&lt;/span&gt;(T);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;
&lt;p&gt;
&lt;span class="lnum"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span class="lnum"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;delegate&lt;/span&gt; T
FactoryFunc&amp;lt;T&amp;gt;();
&lt;/p&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T
Factory&amp;lt;T&amp;gt;(FactoryFunc&amp;lt;T&amp;gt; makeANewT)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T
: &lt;span class="kwrd"&gt;new&lt;/span&gt;()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; T rVal = makeANewT();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (rVal == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; T();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; rVal;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre&gt; Ensure your generic classes support disposable type parameters&lt;br&gt;
&lt;/pre&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetThingsDone()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; T driver = &lt;span class="kwrd"&gt;new&lt;/span&gt; T();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (driver &lt;span class="kwrd"&gt;as&lt;/span&gt; IDisposable)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; driver.DoWork();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;}&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;If drive is a property member in the generic class, you have to implement IDisposable interface. So better to&lt;/pre&gt;
&lt;pre&gt;take it out from generic class.&lt;br&gt;
&lt;/pre&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EngineDriver&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T
: IEngine&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; T
driver;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; EngineDriver(T
driver)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.driver = driver;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetThingsDone()&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; driver.DoWork();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;Use Delegates to define method constrains on Type Parameters&lt;/font&gt;&lt;/strong&gt;
&lt;br&gt;
When it's unwieldy to use an interface to define a constraint, you can define a method
signature and a delegate type that suits your needs. Then you add an instance of that
delegate to the list of the parameters of the generic method. The developers using
your class can use a lambda expression to define that method, writing much less code,
in a much clearer fashion. Developers using your class need to create the lambda expression
that defines the method functionality they need. There's no extra code to support
the syntax of interface-based constraints.
&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Example&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T
Add&amp;lt;T&amp;gt;(T left, T right,&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; Func&amp;lt;T, T, T&amp;gt; AddFunc)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; AddFunc(left,
right);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
In the general case, any method your generic class needs to call can be replaced by
a specific delegate.
&lt;/p&gt;
&lt;p&gt;
It's not a good idea to create generic specializations for base classes when you intend
to support the class and all its descendents.&lt;br&gt;
(That is to say: don’t create a same name generic method in a class as the names in
base classes or derivative classes))
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;If a type needs type-level data members, especially data members involving
the type parameter, make it a generic class. Otherwise, use generic methods.&lt;br&gt;
&lt;/strong&gt;Obviously, not every generic algorithm is suited for generic methods instead
of a generic class. Some simple guidelines can help you determine which to use. In
two cases you must make a generic class: The first occurs when your class stores a
value of one of the &lt;tt&gt;Type&lt;/tt&gt; parameters as part of its internal state. (Collections
are an obvious example.) The second occurs when your class implements a generic interface.
Except for those two cases, you can usually create a nongeneric class and use generic
methods. You'll end up with more granularity in your options for updating the algorithms
in the future.
&lt;/p&gt;
&lt;p&gt;
One common problem for many developers is how to create a method signature for methods
that logically return more than one item. Many developers turn to &lt;tt&gt;ref&lt;/tt&gt; or &lt;tt&gt;out&lt;/tt&gt; parameters
in those cases. But it's better to define generic tuples that can return multiple
discrete values. A tuple is nothing more than a composite with n elements.&lt;br&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;struct&lt;/span&gt; Tuple&amp;lt;T1,
T2&amp;gt; : IEquatable&amp;lt;Tuple&amp;lt;T1, T2&amp;gt;&amp;gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; T1
first;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; T1 First&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; get { &lt;span class="kwrd"&gt;return&lt;/span&gt; first;
}&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; T2
second;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; T2 Second&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; get { &lt;span class="kwrd"&gt;return&lt;/span&gt; second;
}&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; Tuple(T1
f, T2 s)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; first = f;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; second = s;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt; &lt;span class="rem"&gt;// Implementation of IEquatable&amp;lt;Tuple&amp;lt;T1,
T2&amp;gt;&amp;gt; elided&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp; 
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Tuple&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;decimal&lt;/span&gt;&amp;gt;
FindTempForNearestCity&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; soughtCity)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; city = &lt;span class="str"&gt;"algorithmElided"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;decimal&lt;/span&gt; temp
= &lt;span class="kwrd"&gt;decimal&lt;/span&gt;.MinValue; &lt;span class="rem"&gt;// really cold.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Tuple&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;decimal&lt;/span&gt;&amp;gt;(city,
temp);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=d91135ac-13e9-45e7-9601-09c4a6b7a6c2" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,d91135ac-13e9-45e7-9601-09c4a6b7a6c2.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=6b64678c-81b7-4f8c-8261-0c43d09e85b2</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,6b64678c-81b7-4f8c-8261-0c43d09e85b2.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,6b64678c-81b7-4f8c-8261-0c43d09e85b2.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6b64678c-81b7-4f8c-8261-0c43d09e85b2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
in AssemblyInfo.cs<br />
[Assembly:ScriptResource(“Calculator.Resources.Calculator.js”,”Calculator.Resources.MessageResources”,"Messages”)]
</p>
        <p>
When you configure an AJAX-enabled ASP.NET Web site, use only the default value of
UseCookies for the cookieless attribute. Settings that use cookies encoded in the
URL are not supported by the ASP.NET AJAX client script libraries. 
</p>
        <p>
use load event to load view data, use preRender event to save view data
</p>
        <p>
&lt;trace enabled=”true” pageOutput=”false” localOnly = “true” /&gt;<br /></p>
        <p>
Custom server controls that use control state must call the RegisterRequiresControlState
method on each request because registration for control state is not carried over
from request to request during a postback event. It is recommended that registration
occur in the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.init.aspx">Init</a> event. 
</p>
        <p>
System.Web.Management.WebAuditEvent for Security-related Web Events.<br />
System.Web.Management.WebErrorEvent for Web Events caused by problems with configuration
or application code.
</p>
        <p>
aboutPostBack(): Cancel the postback that is currently running<br />
args.set_cancel(true) Cancel this postback
</p>
        <p>
AJAX add error handler code by pageMgr.add_endRequest(errorHandler);<br />
Raised after the response for an asynchronous postback is processed and the page is
updated, or during the processing of the response if there is an error. If an error
occurs, the page is not updated. Use this event to provide customized error notification
to users or to log errors.
</p>
        <p>
Override Evaluate(HttpContext context, Control control) in custom parameter for commands.
</p>
        <p>
Request.ServerVariables[“REMOTE_ADDR”]
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=6b64678c-81b7-4f8c-8261-0c43d09e85b2" />
      </body>
      <title>70-562 part10</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,6b64678c-81b7-4f8c-8261-0c43d09e85b2.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,6b64678c-81b7-4f8c-8261-0c43d09e85b2.aspx</link>
      <pubDate>Wed, 14 Oct 2009 04:03:20 GMT</pubDate>
      <description>&lt;p&gt;
in AssemblyInfo.cs&lt;br&gt;
[Assembly:ScriptResource(“Calculator.Resources.Calculator.js”,”Calculator.Resources.MessageResources”,"Messages”)]
&lt;/p&gt;
&lt;p&gt;
When you configure an AJAX-enabled ASP.NET Web site, use only the default value of
UseCookies for the cookieless attribute. Settings that use cookies encoded in the
URL are not supported by the ASP.NET AJAX client script libraries. 
&lt;/p&gt;
&lt;p&gt;
use load event to load view data, use preRender event to save view data
&lt;/p&gt;
&lt;p&gt;
&amp;lt;trace enabled=”true” pageOutput=”false” localOnly = “true” /&amp;gt;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
Custom server controls that use control state must call the RegisterRequiresControlState
method on each request because registration for control state is not carried over
from request to request during a postback event. It is recommended that registration
occur in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.init.aspx"&gt;Init&lt;/a&gt; event. 
&lt;/p&gt;
&lt;p&gt;
System.Web.Management.WebAuditEvent for Security-related Web Events.&lt;br&gt;
System.Web.Management.WebErrorEvent for Web Events caused by problems with configuration
or application code.
&lt;/p&gt;
&lt;p&gt;
aboutPostBack(): Cancel the postback that is currently running&lt;br&gt;
args.set_cancel(true) Cancel this postback
&lt;/p&gt;
&lt;p&gt;
AJAX add error handler code by pageMgr.add_endRequest(errorHandler);&lt;br&gt;
Raised after the response for an asynchronous postback is processed and the page is
updated, or during the processing of the response if there is an error. If an error
occurs, the page is not updated. Use this event to provide customized error notification
to users or to log errors.
&lt;/p&gt;
&lt;p&gt;
Override Evaluate(HttpContext context, Control control) in custom parameter for commands.
&lt;/p&gt;
&lt;p&gt;
Request.ServerVariables[“REMOTE_ADDR”]
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=6b64678c-81b7-4f8c-8261-0c43d09e85b2" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,6b64678c-81b7-4f8c-8261-0c43d09e85b2.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=86886dd8-99b2-4d3a-8d53-b023804d760a</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,86886dd8-99b2-4d3a-8d53-b023804d760a.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,86886dd8-99b2-4d3a-8d53-b023804d760a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=86886dd8-99b2-4d3a-8d53-b023804d760a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Use ScriptManager.RegisterDataItem method to send data from the server to the client
during asynchronous postbacks, regardless of whether the control receiving the data
is inside an UpdatePanel control. 
<br />
Use REgisterAsyncPOstBackControl for registers a control as a trigger for asynchronous
postbacks.
</p>
        <p>
abortPostBack(): Cancel the postback that is currently running<br />
args_set_cancel(true): Cancel this postback
</p>
        <p>
The partial page postback is managed on the client-side by the <a href="http://msdn.microsoft.com/en-us/library/bb311028.aspx"><code>PageRequestManager</code> object</a>.
Whenever a partial page postback is initiated, the <code>PageRequestManager</code> object
performs the following <i>client-side</i> actions: 
<br /><a title="http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/052808-1.aspx" href="http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/052808-1.aspx">http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/052808-1.aspx</a></p>
        <ol>
          <li>
The <a href="http://msdn.microsoft.com/en-us/library/bb397460.aspx"><code>initializeRequest</code> event</a> is
raised - this is the first event raised during the partial postback life-cycle and
affords us an opportunity to determine the HTML element that triggered the postback
and cancel the postback, if needed. 
</li>
          <li>
The <a href="http://msdn.microsoft.com/en-us/library/bb397432.aspx"><code>beginRequest</code> event</a> is
raised - this event is raised just before the request is sent to the server. The UpdateProgress
control uses this event to displayed it's output. 
</li>
          <li>
The request is sent to the server and the page is re-rendered there. 
</li>
          <li>
The <a href="http://msdn.microsoft.com/en-us/library/bb383832.aspx"><code>pageLoading</code> event</a> is
raised when the server returns its response. 
</li>
          <li>
The <a href="http://msdn.microsoft.com/en-us/library/bb397523.aspx"><code>pageLoaded</code> event</a> is
raised. This event is raised whenever the content on the page is refreshed, be it
via a full page postback or a partial page postback. 
</li>
          <li>
The <a href="http://msdn.microsoft.com/en-us/library/bb383810.aspx"><code>endRequest</code> event</a> is
raised, signalling completion of the partial page postback lifecycle. 
</li>
        </ol>
        <p>
DataSourceID in &lt;asp:BulletedList .. /&gt;
</p>
        <p>
&lt;httpHandlers&gt; &lt;add verb=”*" path=”*.media” validate=”false” type=”Contoso.Web.UI.MultimediaDownloader”
/&gt;&lt;/httpHandlers&gt;<br />
If the Validate property is false, ASP.NET will not attempt to load the class until
the actual matching request comes, potentially delaying the error but improving the
startup time.
</p>
        <p>
$Create shortcut method<br />
Provides a shortcut to the <a href="http://www.asp.net/Ajax/documentation/live/ClientReference/Sys/ComponentClass/ComponentCreateMethod.aspx">create</a> method
of the <a href="http://www.asp.net/Ajax/documentation/live/ClientReference/Sys/ComponentClass/default.aspx">Sys.Component</a> class.
</p>
        <p>
$get<br /><strong><em>$get</em></strong> can be used as shorthand for the <strong><em>document.getElementById</em></strong> and <strong><em>element.getElementById </em></strong>functions. 
The <strong><em>$get</em></strong> shortcut function points to the <a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys.UI/DomElementClass/SysUIDomElementGetElementByIdMethod.aspx">Sys.UI.DomElement.getElementById</a> JavaScript
function which is defined as part of the <a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/default.aspx">ASP.NET
AJAX client side library</a> (which means you will need to include a ScriptManager
on the page to be able to use it).  <strong><em>$get</em></strong> accepts two
parameters, the first is the ID of the DOM element you want to retrieve, the second
is the parent element of where the search starts.  The second parameter is optional
and when it is not supplied defaults to the document element. 
</p>
        <p>
$find<br />
The<strong><em> $find </em></strong>shortcut function allows you to look up an ASP.NET
AJAX client side <a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys/ComponentClass/default.aspx">Component</a> by
it's ID.  Here is a <a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/FindShortcutMethod.aspx">link</a> to
the $find shortcut's documentation and below is the API description.
</p>
        <p>
Template.InstantiateIn(control c)
</p>
        <p>
&lt;asp:AsyncPostBackTrigger&gt; and &lt;asp:PostBackTrigger&gt; childrenAsTriggers
= true;
</p>
        <p>
LoadViewState :control developers can override this method to specify how a custom
server control restores its view state. For more information, see <a href="http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx">ASP.NET
State Management Overview</a>.
</p>
        <pre>public bool HasCapability(
    string delegateName,
    string optionalParameter
)</pre>
        <p>
DataKeyNames property in asp:DetailsView
</p>
        <p>
ASP.NET session state supports several different storage options for session data.
Each option is identified by a value in the <a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.aspx">SessionStateMode</a> enumeration.
The following list describes the available session state modes: 
</p>
        <ul>
          <li>
            <p>
              <a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.inproc.aspx">InProc</a> mode,
which stores session state in memory on the Web server. This is the default.
</p>
          </li>
          <li>
            <p>
              <a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.stateserver.aspx">StateServer</a> mode,
which stores session state in a separate process called the ASP.NET state service.
This ensures that session state is preserved if the Web application is restarted and
also makes session state available to multiple Web servers in a Web farm.
</p>
          </li>
          <li>
            <p>
              <a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.sqlserver.aspx">SQLServer</a> mode
stores session state in a SQL Server database. This ensures that session state is
preserved if the Web application is restarted and also makes session state available
to multiple Web servers in a Web farm.
</p>
          </li>
          <li>
            <p>
              <a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.custom.aspx">Custom</a> mode,
which enables you to specify a custom storage provider.
</p>
          </li>
          <li>
            <p>
              <a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.off.aspx">Off</a> mode,
which disables session state.
</p>
          </li>
        </ul>
        <pre> </pre>
        <pre>
          <a title="http://msdn.microsoft.com/en-us/library/hkx121s4.aspx" href="http://msdn.microsoft.com/en-us/library/hkx121s4.aspx">http://msdn.microsoft.com/en-us/library/hkx121s4.aspx</a>
        </pre>
        <pre>&lt;system.web&gt;
  &lt;deviceFilters&gt;
    &lt;filter
      name="capability"
      compare="capabilityName"
      argument="argument" /&gt;
    &lt;filter
      name="capability"
      type="className"
      method="methodName" /&gt;
  &lt;/deviceFilters&gt;
&lt;/system.web&gt;
</pre>
        <pre>&lt;mobile:Image runat=server ImageURL="bw.gif"&gt;
  &lt;DeviceSpecific&gt;
    &lt;Choice Filter="isColor" ImageURL="colorImg.gif"
      AlternateText="This device cannot display the image." /&gt;
    &lt;Choice Filter="isWML11" ImageURL="myImage.wbmp" /&gt;
    &lt;Choice ImageURL="monoImage.gif" /&gt;
  &lt;/DeviceSpecific&gt;
&lt;/mobile:Image&gt;
</pre>
        <p>
 
</p>
        <p>
If the filter name is omitted, the choice is selected by default. 
</p>
        <p>
ScriptManager.RegisterClientScriptBlock(txtInfo, typeof(TextBox), “txtInfo_Script”,
generatedScript, false);
</p>
        <p>
Disable Request Validation<br />
&lt;%@ Page validateRequest=”false” %&gt;
</p>
        <p>
a new validation control ovverrides the EvaluateIsValid method to validate the value
of the related control.
</p>
        <p>
HttpContext.RewritePath method redirects a request for a resource to another resource
without changing the URL.<br />
S<br />
Redirects a request for a resource to a different path than the one that is indicated
by the requested URL. RewritePath is used in cookieless session state to strip session
IDs from URLs.
</p>
        <p>
Response.Redirect will have 2 request from client browser. Server.Transfer is 1 request
and will not change the path in the browser.
</p>
        <p>
Use Style defined in StyleSheet control<br />
&lt;mobile:Label ID=”MyLabel” Runat=”server” StyleReference=”MyStyleSheet:StyleA”&gt;
&lt;/mobile:Label&gt;
</p>
        <p>
&lt;Compilation debug=”false” Batch=”true”&gt;<br />
debug=false (optimize the performance)<br />
batch=”true” (default, ensure that during the initial request to the application,
the code-behind files for the Web pages are compiled.<br />
If True, eliminates the delay caused by the compilation required when you access a
file for the first time. When this attribute is set to True, ASP.NET <strong>precompiles
all the uncompiled files</strong> in a batch mode, which causes an even longer delay
the first time the files are compiled. However, after this initial delay, the compilation
delay is eliminated on subsequent access of the file. 
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=86886dd8-99b2-4d3a-8d53-b023804d760a" />
      </body>
      <title>70-562 part9</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,86886dd8-99b2-4d3a-8d53-b023804d760a.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,86886dd8-99b2-4d3a-8d53-b023804d760a.aspx</link>
      <pubDate>Tue, 13 Oct 2009 21:19:49 GMT</pubDate>
      <description>&lt;p&gt;
Use ScriptManager.RegisterDataItem method to send data from the server to the client
during asynchronous postbacks, regardless of whether the control receiving the data
is inside an UpdatePanel control. 
&lt;br&gt;
Use REgisterAsyncPOstBackControl for registers a control as a trigger for asynchronous
postbacks.
&lt;/p&gt;
&lt;p&gt;
abortPostBack(): Cancel the postback that is currently running&lt;br&gt;
args_set_cancel(true): Cancel this postback
&lt;/p&gt;
&lt;p&gt;
The partial page postback is managed on the client-side by the &lt;a href="http://msdn.microsoft.com/en-us/library/bb311028.aspx"&gt;&lt;code&gt;PageRequestManager&lt;/code&gt; object&lt;/a&gt;.
Whenever a partial page postback is initiated, the &lt;code&gt;PageRequestManager&lt;/code&gt; object
performs the following &lt;i&gt;client-side&lt;/i&gt; actions: 
&lt;br&gt;
&lt;a title="http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/052808-1.aspx" href="http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/052808-1.aspx"&gt;http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/052808-1.aspx&lt;/a&gt; 
&lt;ol&gt;
&lt;li&gt;
The &lt;a href="http://msdn.microsoft.com/en-us/library/bb397460.aspx"&gt;&lt;code&gt;initializeRequest&lt;/code&gt; event&lt;/a&gt; is
raised - this is the first event raised during the partial postback life-cycle and
affords us an opportunity to determine the HTML element that triggered the postback
and cancel the postback, if needed. 
&lt;li&gt;
The &lt;a href="http://msdn.microsoft.com/en-us/library/bb397432.aspx"&gt;&lt;code&gt;beginRequest&lt;/code&gt; event&lt;/a&gt; is
raised - this event is raised just before the request is sent to the server. The UpdateProgress
control uses this event to displayed it's output. 
&lt;li&gt;
The request is sent to the server and the page is re-rendered there. 
&lt;li&gt;
The &lt;a href="http://msdn.microsoft.com/en-us/library/bb383832.aspx"&gt;&lt;code&gt;pageLoading&lt;/code&gt; event&lt;/a&gt; is
raised when the server returns its response. 
&lt;li&gt;
The &lt;a href="http://msdn.microsoft.com/en-us/library/bb397523.aspx"&gt;&lt;code&gt;pageLoaded&lt;/code&gt; event&lt;/a&gt; is
raised. This event is raised whenever the content on the page is refreshed, be it
via a full page postback or a partial page postback. 
&lt;li&gt;
The &lt;a href="http://msdn.microsoft.com/en-us/library/bb383810.aspx"&gt;&lt;code&gt;endRequest&lt;/code&gt; event&lt;/a&gt; is
raised, signalling completion of the partial page postback lifecycle. 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
DataSourceID in &amp;lt;asp:BulletedList .. /&amp;gt;
&lt;/p&gt;
&lt;p&gt;
&amp;lt;httpHandlers&amp;gt; &amp;lt;add verb=”*" path=”*.media” validate=”false” type=”Contoso.Web.UI.MultimediaDownloader”
/&amp;gt;&amp;lt;/httpHandlers&amp;gt;&lt;br&gt;
If the Validate property is false, ASP.NET will not attempt to load the class until
the actual matching request comes, potentially delaying the error but improving the
startup time.
&lt;/p&gt;
&lt;p&gt;
$Create shortcut method&lt;br&gt;
Provides a shortcut to the &lt;a href="http://www.asp.net/Ajax/documentation/live/ClientReference/Sys/ComponentClass/ComponentCreateMethod.aspx"&gt;create&lt;/a&gt; method
of the &lt;a href="http://www.asp.net/Ajax/documentation/live/ClientReference/Sys/ComponentClass/default.aspx"&gt;Sys.Component&lt;/a&gt; class.
&lt;/p&gt;
&lt;p&gt;
$get&lt;br&gt;
&lt;strong&gt;&lt;em&gt;$get&lt;/em&gt;&lt;/strong&gt; can be used as shorthand for the &lt;strong&gt;&lt;em&gt;document.getElementById&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;element.getElementById &lt;/em&gt;&lt;/strong&gt;functions.&amp;nbsp;
The &lt;strong&gt;&lt;em&gt;$get&lt;/em&gt;&lt;/strong&gt; shortcut function points to the &lt;a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys.UI/DomElementClass/SysUIDomElementGetElementByIdMethod.aspx"&gt;Sys.UI.DomElement.getElementById&lt;/a&gt; JavaScript
function which is defined as part of the &lt;a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/default.aspx"&gt;ASP.NET
AJAX client side library&lt;/a&gt; (which means you will need to include a ScriptManager
on the page to be able to use it).&amp;nbsp; &lt;strong&gt;&lt;em&gt;$get&lt;/em&gt;&lt;/strong&gt; accepts two
parameters, the first is the ID of the DOM element you want to retrieve, the second
is the parent element of where the search starts.&amp;nbsp; The second parameter is optional
and when it is not supplied defaults to the document element. 
&lt;/p&gt;
&lt;p&gt;
$find&lt;br&gt;
The&lt;strong&gt;&lt;em&gt; $find &lt;/em&gt;&lt;/strong&gt;shortcut function allows you to look up an ASP.NET
AJAX client side &lt;a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys/ComponentClass/default.aspx"&gt;Component&lt;/a&gt; by
it's ID.&amp;nbsp; Here is a &lt;a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/FindShortcutMethod.aspx"&gt;link&lt;/a&gt; to
the $find shortcut's documentation and below is the API description.
&lt;/p&gt;
&lt;p&gt;
Template.InstantiateIn(control c)
&lt;/p&gt;
&lt;p&gt;
&amp;lt;asp:AsyncPostBackTrigger&amp;gt; and &amp;lt;asp:PostBackTrigger&amp;gt; childrenAsTriggers
= true;
&lt;/p&gt;
&lt;p&gt;
LoadViewState :control developers can override this method to specify how a custom
server control restores its view state. For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx"&gt;ASP.NET
State Management Overview&lt;/a&gt;.
&lt;/p&gt;
&lt;pre&gt;public bool HasCapability(
    string delegateName,
    string optionalParameter
)&lt;/pre&gt;
&lt;p&gt;
DataKeyNames property in asp:DetailsView
&lt;/p&gt;
&lt;p&gt;
ASP.NET session state supports several different storage options for session data.
Each option is identified by a value in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.aspx"&gt;SessionStateMode&lt;/a&gt; enumeration.
The following list describes the available session state modes: 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.inproc.aspx"&gt;InProc&lt;/a&gt; mode,
which stores session state in memory on the Web server. This is the default.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.stateserver.aspx"&gt;StateServer&lt;/a&gt; mode,
which stores session state in a separate process called the ASP.NET state service.
This ensures that session state is preserved if the Web application is restarted and
also makes session state available to multiple Web servers in a Web farm.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.sqlserver.aspx"&gt;SQLServer&lt;/a&gt; mode
stores session state in a SQL Server database. This ensures that session state is
preserved if the Web application is restarted and also makes session state available
to multiple Web servers in a Web farm.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.custom.aspx"&gt;Custom&lt;/a&gt; mode,
which enables you to specify a custom storage provider.
&lt;/p&gt;
&lt;li&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemode.off.aspx"&gt;Off&lt;/a&gt; mode,
which disables session state.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;a title="http://msdn.microsoft.com/en-us/library/hkx121s4.aspx" href="http://msdn.microsoft.com/en-us/library/hkx121s4.aspx"&gt;http://msdn.microsoft.com/en-us/library/hkx121s4.aspx&lt;/a&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;lt;system.web&amp;gt;
  &amp;lt;deviceFilters&amp;gt;
    &amp;lt;filter
      name="capability"
      compare="capabilityName"
      argument="argument" /&amp;gt;
    &amp;lt;filter
      name="capability"
      type="className"
      method="methodName" /&amp;gt;
  &amp;lt;/deviceFilters&amp;gt;
&amp;lt;/system.web&amp;gt;
&lt;/pre&gt;
&lt;pre&gt;&amp;lt;mobile:Image runat=server ImageURL="bw.gif"&amp;gt;
  &amp;lt;DeviceSpecific&amp;gt;
    &amp;lt;Choice Filter="isColor" ImageURL="colorImg.gif"
      AlternateText="This device cannot display the image." /&amp;gt;
    &amp;lt;Choice Filter="isWML11" ImageURL="myImage.wbmp" /&amp;gt;
    &amp;lt;Choice ImageURL="monoImage.gif" /&amp;gt;
  &amp;lt;/DeviceSpecific&amp;gt;
&amp;lt;/mobile:Image&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
If the filter name is omitted, the choice is selected by default. 
&lt;/p&gt;
&lt;p&gt;
ScriptManager.RegisterClientScriptBlock(txtInfo, typeof(TextBox), “txtInfo_Script”,
generatedScript, false);
&lt;/p&gt;
&lt;p&gt;
Disable Request Validation&lt;br&gt;
&amp;lt;%@ Page validateRequest=”false” %&amp;gt;
&lt;/p&gt;
&lt;p&gt;
a new validation control ovverrides the EvaluateIsValid method to validate the value
of the related control.
&lt;/p&gt;
&lt;p&gt;
HttpContext.RewritePath method redirects a request for a resource to another resource
without changing the URL.&lt;br&gt;
S&lt;br&gt;
Redirects a request for a resource to a different path than the one that is indicated
by the requested URL. RewritePath is used in cookieless session state to strip session
IDs from URLs.
&lt;/p&gt;
&lt;p&gt;
Response.Redirect will have 2 request from client browser. Server.Transfer is 1 request
and will not change the path in the browser.
&lt;/p&gt;
&lt;p&gt;
Use Style defined in StyleSheet control&lt;br&gt;
&amp;lt;mobile:Label ID=”MyLabel” Runat=”server” StyleReference=”MyStyleSheet:StyleA”&amp;gt;
&amp;lt;/mobile:Label&amp;gt;
&lt;/p&gt;
&lt;p&gt;
&amp;lt;Compilation debug=”false” Batch=”true”&amp;gt;&lt;br&gt;
debug=false (optimize the performance)&lt;br&gt;
batch=”true” (default, ensure that during the initial request to the application,
the code-behind files for the Web pages are compiled.&lt;br&gt;
If True, eliminates the delay caused by the compilation required when you access a
file for the first time. When this attribute is set to True, ASP.NET &lt;strong&gt;precompiles
all the uncompiled files&lt;/strong&gt; in a batch mode, which causes an even longer delay
the first time the files are compiled. However, after this initial delay, the compilation
delay is eliminated on subsequent access of the file. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=86886dd8-99b2-4d3a-8d53-b023804d760a" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,86886dd8-99b2-4d3a-8d53-b023804d760a.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=b86bd59e-b39d-4935-92a8-a2dff27ca43a</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,b86bd59e-b39d-4935-92a8-a2dff27ca43a.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,b86bd59e-b39d-4935-92a8-a2dff27ca43a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b86bd59e-b39d-4935-92a8-a2dff27ca43a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
ProfileOnMigrateAnonymous(…)
</p>
        <p>
4 types of authentication: Windows, forms, passport anonymous<br />
&lt;deny users=”?" /&gt; and &lt;allow users=”*" /&gt;<br />
FormsAuthentication.Authenticate<br />
FormsAuthentication.RedirectFromLoginPage(…)<br />
FormsAuthentication.SignOut()
</p>
        <p>
SeesionState in mobile website<br />
&lt;sessionState cookieless=”true”/&gt;<br />
&lt;mobileControls cookielessDatadictionaryType=”System.web.Mobile.CookielessData”
/&gt;<br /></p>
        <p>
User-Agent HTTP header<br />
browserCaps relies on XML files that contain a hierarchal structure of browser definitions.
The default location is at .net framework folder .\CONFIG\Browser<br />
ASP.BrowserCapsFactory.dll and HttpBroserCapabilities class<br />
Request.Browser.IsMobileDevice
</p>
        <p>
Search Target machine and launch conditions<br />
Pregrouped Launch Conditions
</p>
        <p>
MSI command-line options.
</p>
        <p>
The Copy Web tool doesn not merge changes within a single file; it only does complete
file copies.
</p>
        <p>
By default, a Web Setup Project checks for an IIS version later than 4.
</p>
        <p>
Precompiling Web Applications.
</p>
        <p>
Application caching 
<br />
The cache object is available as a property of the Page object.<br />
absoluteExpiration and slidingExpiration<br />
onRemoveCallback<br />
CacheDependency and AggregateCacheDependency<br />
Cache.Insert(“FileCache”, “CacheContents”, new System.Web.Caching.CacheDependency(Server.MapPath(“SourceFile.xml”)))
</p>
        <p>
Page output caching<br />
With page output caching, ASP.NET can keep a copy of a rendered ASP.NET Web page in
memory on the server.<br />
&lt;%@ OutputCache Duration=”15” VaryByParam=”location;count” %&gt;<br />
Use REspoinse.Cache object to do the run-time decision about output caching<br />
Response.WriteSubstitution method and Subsitution control (with MethodName property)<br />
HttpValidationStatus and Response.Cache.AddValidationCallback to invalidate the page
output caching if needed.<br />
Add CacheProfile in Web.config and then reference it in page<br />
&lt;%@ OutputCache CacheProfile=”One MInuteProfile” VaryByParam=”none” %&gt;
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=b86bd59e-b39d-4935-92a8-a2dff27ca43a" />
      </body>
      <title>70-562 part8</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,b86bd59e-b39d-4935-92a8-a2dff27ca43a.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,b86bd59e-b39d-4935-92a8-a2dff27ca43a.aspx</link>
      <pubDate>Thu, 08 Oct 2009 20:16:02 GMT</pubDate>
      <description>&lt;p&gt;
ProfileOnMigrateAnonymous(…)
&lt;/p&gt;
&lt;p&gt;
4 types of authentication: Windows, forms, passport anonymous&lt;br&gt;
&amp;lt;deny users=”?" /&amp;gt; and &amp;lt;allow users=”*" /&amp;gt;&lt;br&gt;
FormsAuthentication.Authenticate&lt;br&gt;
FormsAuthentication.RedirectFromLoginPage(…)&lt;br&gt;
FormsAuthentication.SignOut()
&lt;/p&gt;
&lt;p&gt;
SeesionState in mobile website&lt;br&gt;
&amp;lt;sessionState cookieless=”true”/&amp;gt;&lt;br&gt;
&amp;lt;mobileControls cookielessDatadictionaryType=”System.web.Mobile.CookielessData”
/&amp;gt;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
User-Agent HTTP header&lt;br&gt;
browserCaps relies on XML files that contain a hierarchal structure of browser definitions.
The default location is at .net framework folder .\CONFIG\Browser&lt;br&gt;
ASP.BrowserCapsFactory.dll and HttpBroserCapabilities class&lt;br&gt;
Request.Browser.IsMobileDevice
&lt;/p&gt;
&lt;p&gt;
Search Target machine and launch conditions&lt;br&gt;
Pregrouped Launch Conditions
&lt;/p&gt;
&lt;p&gt;
MSI command-line options.
&lt;/p&gt;
&lt;p&gt;
The Copy Web tool doesn not merge changes within a single file; it only does complete
file copies.
&lt;/p&gt;
&lt;p&gt;
By default, a Web Setup Project checks for an IIS version later than 4.
&lt;/p&gt;
&lt;p&gt;
Precompiling Web Applications.
&lt;/p&gt;
&lt;p&gt;
Application caching 
&lt;br&gt;
The cache object is available as a property of the Page object.&lt;br&gt;
absoluteExpiration and slidingExpiration&lt;br&gt;
onRemoveCallback&lt;br&gt;
CacheDependency and AggregateCacheDependency&lt;br&gt;
Cache.Insert(“FileCache”, “CacheContents”, new System.Web.Caching.CacheDependency(Server.MapPath(“SourceFile.xml”)))
&lt;/p&gt;
&lt;p&gt;
Page output caching&lt;br&gt;
With page output caching, ASP.NET can keep a copy of a rendered ASP.NET Web page in
memory on the server.&lt;br&gt;
&amp;lt;%@ OutputCache Duration=”15” VaryByParam=”location;count” %&amp;gt;&lt;br&gt;
Use REspoinse.Cache object to do the run-time decision about output caching&lt;br&gt;
Response.WriteSubstitution method and Subsitution control (with MethodName property)&lt;br&gt;
HttpValidationStatus and Response.Cache.AddValidationCallback to invalidate the page
output caching if needed.&lt;br&gt;
Add CacheProfile in Web.config and then reference it in page&lt;br&gt;
&amp;lt;%@ OutputCache CacheProfile=”One MInuteProfile” VaryByParam=”none” %&amp;gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=b86bd59e-b39d-4935-92a8-a2dff27ca43a" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,b86bd59e-b39d-4935-92a8-a2dff27ca43a.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=d2b64932-5922-4db5-a53b-97b2b64825ec</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,d2b64932-5922-4db5-a53b-97b2b64825ec.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,d2b64932-5922-4db5-a53b-97b2b64825ec.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d2b64932-5922-4db5-a53b-97b2b64825ec</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The <strong>templated user control</strong> can be used to provide data that is to
be rendered but allows the Web page designer to specify the format of the data.
</p>
        <p>
A custom Web control is a control that inherits from a WebServer control. It can be
compiled into a dll and put to GAC.<br />
To create a custom version of existing control. YOu need to override the Render method
and use HtmlTextWriter to output your display information.
</p>
        <p>
Add icon to your control [ToolboxBitmap(typeof(LabeledTextbox), “MyUserControls.LabeledTextBox.bmp”)]
</p>
        <p>
[DefaultProperty(“PromptText”)]<br />
public class LabeledTextBox : TextBox
</p>
        <p>
Use ToolboxDataAttribute to control the the Markup generated for your Custom Control.
Also use [assembly: TagPrefix(“MyUserControls”, “muc”0] to change the prefix.
</p>
        <p>
Create a Custom Designer for a Custom Control (p693)
</p>
        <p>
Composite control inherits from CompositeControl class and overrides the CreateChildControls
method. It has no designer screen.
</p>
        <p>
Page_Error event handler 
<br />
Server.GetLastError().Message<br />
Server.ClearError()
</p>
        <p>
Application_Error event handler and Server.Transfer
</p>
        <p>
WebConfigurationManager<br />
GetSection<br />
GetSectionGroup
</p>
        <p>
Asynchronous Web Page<br />
Async attribute in Page declarative<br />
Create event to start and end your asynchronous code (BeginProcessRequest, EndProcessRequest)<br />
AddOnPreRenderCompleteAsync(bh, eh)
</p>
        <p>
Customize hander should implement IHttpHandler<br />
IsResuable property and ProcessRequest method
</p>
        <p>
Request.Browser HttpBrowserCapabilities<br />
Page.Header
</p>
        <p>
&lt;%@ Page Debug=”true” … %&gt;<br />
We can define specific page for various HTTP status codes<br />
Remote Debugging Monitor (Msvsmon.exe)
</p>
        <p>
&lt;%@ Page trace=”true” … /&gt;<br />
View Trace data on a virtual page named Trace.axd
</p>
        <p>
Sys.Debug for AJAX client debugging
</p>
        <p>
ASP.NET health monitoring
</p>
        <p>
Local Resource file: &lt;PageName&gt;.aspx.&lt;LanguageId&gt;.resx<br />
meta:resourcekey<br />
Language preference option in Browser
</p>
        <p>
Global Resources<br />
&lt;%$ Resources:LocalizedText, Greeting %&gt;<br />
Label1.Text = Resources.LocalizedText.Greeting;<br />
Store local resources in the App_LocalResources folder
</p>
        <p>
To localize static text that is not part of a control, you can either convert it to
a control or use the Localize control. It functions much like the Literal control.<br />
GetLocalResourceObject method and GetGlobalResourceObject method.<br />
Global resources should be stored in the App_GlobalResources folder
</p>
        <p>
&lt;div style=’height: expression(document.body.clientHeight / 2); width: expression(document.body.clientWidth
/ 2); ‘&gt;<br />
Culture: This object determines the results of culture-dependent functions, such as
the date, number, and currency formatting. You can only define the Culture object
with specific cultures that define both language and regional formatting requirements.
You can not define the Culture object with neutral cultures that define only a language.<br />
UICulture This property determines which global or local resources are loaded for
the page. You can define UICulture with either neutral or specific cultures.
</p>
        <p>
You define the Culture and UICulture properties by overriding the page’s InitializeCulture
method.<br />
CultureInfo.GetCultures(CultureTypes enumeration)<br />
&lt;globalization uiculture=”es” culture=”es-MX” /&gt;<br />
&lt;%@ Page uiculture=”es” culture=”es-MX” %&gt;
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=d2b64932-5922-4db5-a53b-97b2b64825ec" />
      </body>
      <title>70-562 part7</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,d2b64932-5922-4db5-a53b-97b2b64825ec.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,d2b64932-5922-4db5-a53b-97b2b64825ec.aspx</link>
      <pubDate>Wed, 07 Oct 2009 20:52:21 GMT</pubDate>
      <description>&lt;p&gt;
The &lt;strong&gt;templated user control&lt;/strong&gt; can be used to provide data that is to
be rendered but allows the Web page designer to specify the format of the data.
&lt;/p&gt;
&lt;p&gt;
A custom Web control is a control that inherits from a WebServer control. It can be
compiled into a dll and put to GAC.&lt;br&gt;
To create a custom version of existing control. YOu need to override the Render method
and use HtmlTextWriter to output your display information.
&lt;/p&gt;
&lt;p&gt;
Add icon to your control [ToolboxBitmap(typeof(LabeledTextbox), “MyUserControls.LabeledTextBox.bmp”)]
&lt;/p&gt;
&lt;p&gt;
[DefaultProperty(“PromptText”)]&lt;br&gt;
public class LabeledTextBox : TextBox
&lt;/p&gt;
&lt;p&gt;
Use ToolboxDataAttribute to control the the Markup generated for your Custom Control.
Also use [assembly: TagPrefix(“MyUserControls”, “muc”0] to change the prefix.
&lt;/p&gt;
&lt;p&gt;
Create a Custom Designer for a Custom Control (p693)
&lt;/p&gt;
&lt;p&gt;
Composite control inherits from CompositeControl class and overrides the CreateChildControls
method. It has no designer screen.
&lt;/p&gt;
&lt;p&gt;
Page_Error event handler 
&lt;br&gt;
Server.GetLastError().Message&lt;br&gt;
Server.ClearError()
&lt;/p&gt;
&lt;p&gt;
Application_Error event handler and Server.Transfer
&lt;/p&gt;
&lt;p&gt;
WebConfigurationManager&lt;br&gt;
GetSection&lt;br&gt;
GetSectionGroup
&lt;/p&gt;
&lt;p&gt;
Asynchronous Web Page&lt;br&gt;
Async attribute in Page declarative&lt;br&gt;
Create event to start and end your asynchronous code (BeginProcessRequest, EndProcessRequest)&lt;br&gt;
AddOnPreRenderCompleteAsync(bh, eh)
&lt;/p&gt;
&lt;p&gt;
Customize hander should implement IHttpHandler&lt;br&gt;
IsResuable property and ProcessRequest method
&lt;/p&gt;
&lt;p&gt;
Request.Browser HttpBrowserCapabilities&lt;br&gt;
Page.Header
&lt;/p&gt;
&lt;p&gt;
&amp;lt;%@ Page Debug=”true” … %&amp;gt;&lt;br&gt;
We can define specific page for various HTTP status codes&lt;br&gt;
Remote Debugging Monitor (Msvsmon.exe)
&lt;/p&gt;
&lt;p&gt;
&amp;lt;%@ Page trace=”true” … /&amp;gt;&lt;br&gt;
View Trace data on a virtual page named Trace.axd
&lt;/p&gt;
&lt;p&gt;
Sys.Debug for AJAX client debugging
&lt;/p&gt;
&lt;p&gt;
ASP.NET health monitoring
&lt;/p&gt;
&lt;p&gt;
Local Resource file: &amp;lt;PageName&amp;gt;.aspx.&amp;lt;LanguageId&amp;gt;.resx&lt;br&gt;
meta:resourcekey&lt;br&gt;
Language preference option in Browser
&lt;/p&gt;
&lt;p&gt;
Global Resources&lt;br&gt;
&amp;lt;%$ Resources:LocalizedText, Greeting %&amp;gt;&lt;br&gt;
Label1.Text = Resources.LocalizedText.Greeting;&lt;br&gt;
Store local resources in the App_LocalResources folder
&lt;/p&gt;
&lt;p&gt;
To localize static text that is not part of a control, you can either convert it to
a control or use the Localize control. It functions much like the Literal control.&lt;br&gt;
GetLocalResourceObject method and GetGlobalResourceObject method.&lt;br&gt;
Global resources should be stored in the App_GlobalResources folder
&lt;/p&gt;
&lt;p&gt;
&amp;lt;div style=’height: expression(document.body.clientHeight / 2); width: expression(document.body.clientWidth
/ 2); ‘&amp;gt;&lt;br&gt;
Culture: This object determines the results of culture-dependent functions, such as
the date, number, and currency formatting. You can only define the Culture object
with specific cultures that define both language and regional formatting requirements.
You can not define the Culture object with neutral cultures that define only a language.&lt;br&gt;
UICulture This property determines which global or local resources are loaded for
the page. You can define UICulture with either neutral or specific cultures.
&lt;/p&gt;
&lt;p&gt;
You define the Culture and UICulture properties by overriding the page’s InitializeCulture
method.&lt;br&gt;
CultureInfo.GetCultures(CultureTypes enumeration)&lt;br&gt;
&amp;lt;globalization uiculture=”es” culture=”es-MX” /&amp;gt;&lt;br&gt;
&amp;lt;%@ Page uiculture=”es” culture=”es-MX” %&amp;gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=d2b64932-5922-4db5-a53b-97b2b64825ec" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,d2b64932-5922-4db5-a53b-97b2b64825ec.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=3a0d54ca-0543-4012-b2ca-95569eb90733</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,3a0d54ca-0543-4012-b2ca-95569eb90733.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,3a0d54ca-0543-4012-b2ca-95569eb90733.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=3a0d54ca-0543-4012-b2ca-95569eb90733</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The ObjectDataSource control is responsible for the lifetime of the object. It creates
it and dispose of it. Therefore, the business layer code should be written in a stateless
manner. Alternatively, if the business layer uses static methods, the ObjectDataSource
an use these methods without creating an instance of the actual business object.
</p>
        <p>
DataObject and DataObjectMethod attributes.
</p>
        <p>
SqlDataSource can work with ODBC and OLE DB<br />
SQlDataSource.DataSourceMode
</p>
        <p>
SiteMapDataSource: StartingNodeUrl, ShowStartingNode, StartFromCurrentNode, StartingNodeOffset
</p>
        <p>
&lt;%# Eval(“Vin”) %&gt;<br />
&lt;%# Eval(“Price”, “{0:C}”) %&gt; 
<br />
Eval is one-way (read-only) data binding<br /><br />
AppendDataBoundItems in ListControl can be used to keep all items that are currently
in the ListControl in addition to appending the items from the data binding. 
</p>
        <p>
The DetailsView does not directly support sorting, whereas the GridView does.. GirdView
does not automatically support inserting new records, whereas the DetailsView does
support this feature.
</p>
        <p>
Like the DetailsView, the FormView control is used to display a single record from
a data source. However, the FormView control can allows developers to create templates
that define how the data should be displayed.
</p>
        <p>
FormView supports mutiple templates while Repeater control only support ItemTemplate.
</p>
        <p>
ASP.NET Web Service : Set the Web service’s generated client proxy’s Credentials property
to the newly created CredentialCache object.
</p>
        <p>
WCF is a unifying programming model. It is meant to define a singular way for writing
services and thereby unify things like Web services(.asmx), .Net Remoting, Message
Queue (MSMQ), Enterprise Services (COM+), and Web Services Enhancements (WSE). It
doesn’t replace these technologies on a individual basis. Instead, it provides a single
programming model that you can use to take advantage of all of these items at once.
With WCF, you can create a single service that can be exposed as HTTP, TCP, named
pipes, and so on. You also have multiple hosting options.
</p>
        <p>
EndPoint = A (address) + B (binding) + C (contract) 
<br />
You can edit the WCF configuration information by using Service Configuration Editor
(right click Web.config and choose Edit Wcf Configuration)
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=3a0d54ca-0543-4012-b2ca-95569eb90733" />
      </body>
      <title>70-562 PART6</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,3a0d54ca-0543-4012-b2ca-95569eb90733.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,3a0d54ca-0543-4012-b2ca-95569eb90733.aspx</link>
      <pubDate>Wed, 07 Oct 2009 13:51:44 GMT</pubDate>
      <description>&lt;p&gt;
The ObjectDataSource control is responsible for the lifetime of the object. It creates
it and dispose of it. Therefore, the business layer code should be written in a stateless
manner. Alternatively, if the business layer uses static methods, the ObjectDataSource
an use these methods without creating an instance of the actual business object.
&lt;/p&gt;
&lt;p&gt;
DataObject and DataObjectMethod attributes.
&lt;/p&gt;
&lt;p&gt;
SqlDataSource can work with ODBC and OLE DB&lt;br&gt;
SQlDataSource.DataSourceMode
&lt;/p&gt;
&lt;p&gt;
SiteMapDataSource: StartingNodeUrl, ShowStartingNode, StartFromCurrentNode, StartingNodeOffset
&lt;/p&gt;
&lt;p&gt;
&amp;lt;%# Eval(“Vin”) %&amp;gt;&lt;br&gt;
&amp;lt;%# Eval(“Price”, “{0:C}”) %&amp;gt; 
&lt;br&gt;
Eval is one-way (read-only) data binding&lt;br&gt;
&lt;br&gt;
AppendDataBoundItems in ListControl can be used to keep all items that are currently
in the ListControl in addition to appending the items from the data binding. 
&lt;/p&gt;
&lt;p&gt;
The DetailsView does not directly support sorting, whereas the GridView does.. GirdView
does not automatically support inserting new records, whereas the DetailsView does
support this feature.
&lt;/p&gt;
&lt;p&gt;
Like the DetailsView, the FormView control is used to display a single record from
a data source. However, the FormView control can allows developers to create templates
that define how the data should be displayed.
&lt;/p&gt;
&lt;p&gt;
FormView supports mutiple templates while Repeater control only support ItemTemplate.
&lt;/p&gt;
&lt;p&gt;
ASP.NET Web Service : Set the Web service’s generated client proxy’s Credentials property
to the newly created CredentialCache object.
&lt;/p&gt;
&lt;p&gt;
WCF is a unifying programming model. It is meant to define a singular way for writing
services and thereby unify things like Web services(.asmx), .Net Remoting, Message
Queue (MSMQ), Enterprise Services (COM+), and Web Services Enhancements (WSE). It
doesn’t replace these technologies on a individual basis. Instead, it provides a single
programming model that you can use to take advantage of all of these items at once.
With WCF, you can create a single service that can be exposed as HTTP, TCP, named
pipes, and so on. You also have multiple hosting options.
&lt;/p&gt;
&lt;p&gt;
EndPoint = A (address) + B (binding) + C (contract) 
&lt;br&gt;
You can edit the WCF configuration information by using Service Configuration Editor
(right click Web.config and choose Edit Wcf Configuration)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=3a0d54ca-0543-4012-b2ca-95569eb90733" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,3a0d54ca-0543-4012-b2ca-95569eb90733.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=003e9956-9912-4913-9f0a-f4a8384724a9</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,003e9956-9912-4913-9f0a-f4a8384724a9.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,003e9956-9912-4913-9f0a-f4a8384724a9.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=003e9956-9912-4913-9f0a-f4a8384724a9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
use SqlMetal.exe to generate DBML file and code file<br />
use XmlReaderSettings and XmlReader.Create to validate XML
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=003e9956-9912-4913-9f0a-f4a8384724a9" />
      </body>
      <title>70-562 part5</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,003e9956-9912-4913-9f0a-f4a8384724a9.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,003e9956-9912-4913-9f0a-f4a8384724a9.aspx</link>
      <pubDate>Tue, 06 Oct 2009 02:29:55 GMT</pubDate>
      <description>&lt;p&gt;
use SqlMetal.exe to generate DBML file and code file&lt;br&gt;
use XmlReaderSettings and XmlReader.Create to validate XML
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=003e9956-9912-4913-9f0a-f4a8384724a9" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,003e9956-9912-4913-9f0a-f4a8384724a9.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=4cf248f4-a9c1-49a1-bd48-01bda30bd40d</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,4cf248f4-a9c1-49a1-bd48-01bda30bd40d.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,4cf248f4-a9c1-49a1-bd48-01bda30bd40d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4cf248f4-a9c1-49a1-bd48-01bda30bd40d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
DataRow has a RowState property: Detached, Added, Unchanged, Modified, Deleted<br />
Holding multiple copies of data with the DataRowVersion: Current, Default, Original,
Proposed<br />
Resetting the RowState with AcceptChanges and RejectChanges<br />
Explicit changing RowState with the SetAdded and SetModified methods<br />
DataTable.Copy will copy both schema and data while DataTable.Clone will only copy
schema.<br />
Importing DataRow Object into a DataTable
</p>
        <p>
Dataview is seeentially an index collection.
</p>
        <p>
DataSet contains a collection of DataTable and DataRelation bojects.<br />
XmlWriteMode.DiffGram 
</p>
        <p>
aspnet_regiis –pef “ConnectionStrings” “C”\..\EncryptWebSite”<br />
aspnet_regiis –pdf “ConnectionStrings” “C”\..\EncryptWebSite”
</p>
        <p>
DataReader rdr = cmd.ExecuteReader();<br />
DataTable publishers = new DataTable();<br />
publishers.Load(rdr, LoadOption.Upsert)
</p>
        <p>
Using multiple Active Result Sets (MARS) to execute multiple commands on a connection.
</p>
        <p>
DBProviderFactory class 
<br />
ProviderList = System.Data.Common.DbProviderFactories.GetFactoryClasses();<br />
Enumerate Data Sources<br />
DataTable sources = factory.CreateDataSourceEnumerator().GetDataSources();
</p>
        <p>
Catch DBException<br />
The connection classes contain an event called InfoMessage that can be used to retrieve
general and error information from the database. 
</p>
        <p>
IAsyncResult object’s AsyncWaitHandle property was used to wait until the command
finished executing.
</p>
        <p>
To read BLOB data, the ExecuteReader method should be executed with the CommandBehavior.SequentialAccess
parameter. 
<br />
Also it needs to use reader.GetBytes(..) to read data.<br />
TEXTPTR function and UPDATETEXT Command
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=4cf248f4-a9c1-49a1-bd48-01bda30bd40d" />
      </body>
      <title>70-562 part4</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,4cf248f4-a9c1-49a1-bd48-01bda30bd40d.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,4cf248f4-a9c1-49a1-bd48-01bda30bd40d.aspx</link>
      <pubDate>Mon, 05 Oct 2009 21:30:50 GMT</pubDate>
      <description>&lt;p&gt;
DataRow has a RowState property: Detached, Added, Unchanged, Modified, Deleted&lt;br&gt;
Holding multiple copies of data with the DataRowVersion: Current, Default, Original,
Proposed&lt;br&gt;
Resetting the RowState with AcceptChanges and RejectChanges&lt;br&gt;
Explicit changing RowState with the SetAdded and SetModified methods&lt;br&gt;
DataTable.Copy will copy both schema and data while DataTable.Clone will only copy
schema.&lt;br&gt;
Importing DataRow Object into a DataTable
&lt;/p&gt;
&lt;p&gt;
Dataview is seeentially an index collection.
&lt;/p&gt;
&lt;p&gt;
DataSet contains a collection of DataTable and DataRelation bojects.&lt;br&gt;
XmlWriteMode.DiffGram 
&lt;/p&gt;
&lt;p&gt;
aspnet_regiis –pef “ConnectionStrings” “C”\..\EncryptWebSite”&lt;br&gt;
aspnet_regiis –pdf “ConnectionStrings” “C”\..\EncryptWebSite”
&lt;/p&gt;
&lt;p&gt;
DataReader rdr = cmd.ExecuteReader();&lt;br&gt;
DataTable publishers = new DataTable();&lt;br&gt;
publishers.Load(rdr, LoadOption.Upsert)
&lt;/p&gt;
&lt;p&gt;
Using multiple Active Result Sets (MARS) to execute multiple commands on a connection.
&lt;/p&gt;
&lt;p&gt;
DBProviderFactory class 
&lt;br&gt;
ProviderList = System.Data.Common.DbProviderFactories.GetFactoryClasses();&lt;br&gt;
Enumerate Data Sources&lt;br&gt;
DataTable sources = factory.CreateDataSourceEnumerator().GetDataSources();
&lt;/p&gt;
&lt;p&gt;
Catch DBException&lt;br&gt;
The connection classes contain an event called InfoMessage that can be used to retrieve
general and error information from the database. 
&lt;/p&gt;
&lt;p&gt;
IAsyncResult object’s AsyncWaitHandle property was used to wait until the command
finished executing.
&lt;/p&gt;
&lt;p&gt;
To read BLOB data, the ExecuteReader method should be executed with the CommandBehavior.SequentialAccess
parameter. 
&lt;br&gt;
Also it needs to use reader.GetBytes(..) to read data.&lt;br&gt;
TEXTPTR function and UPDATETEXT Command
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=4cf248f4-a9c1-49a1-bd48-01bda30bd40d" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,4cf248f4-a9c1-49a1-bd48-01bda30bd40d.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=6d7a160d-5727-4da5-b1c9-b30a2c311c6e</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,6d7a160d-5727-4da5-b1c9-b30a2c311c6e.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,6d7a160d-5727-4da5-b1c9-b30a2c311c6e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6d7a160d-5727-4da5-b1c9-b30a2c311c6e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>Page.ViewState</strong> property provides a dictionary object for retaining
values between multiple requests for the ame page. The object is of the type <strong>StateBag</strong>. 
Hidden field <strong>__ViewState. </strong>The view state includes a message authentication
code (MAC). Or you can use ViewStateEncryptionMode property of the Page object to
protect the viewstate.
</p>
        <p>
Set to ControlEnableViewState to false to improve the performance on the large data
input form. (data state and control state)<br />
Control state allows you to store property value information that is specific to a
control. This state cannot be turned off and therefore should not be used in lieu
of view state. (Override OnInit, call Page.RegisterRequiresControlState method, override
the SaveControlState mthod)
</p>
        <p>
Hidden Fields control only store informaiton for a single page. Ti has no built-in
compression, encryption, hashing, or chunking. It only works with HTTP POST.
</p>
        <p>
Cookie’s Path and Domain propoerty. 
<br />
Response.Cookies[“Info”][“FirstName”].value = “Tony”; //store multiple values in a
Cookie
</p>
        <p>
Should validate the query string. Also you should always encode cookie or query string
values using Server.HtmlEncode before displaying the value in an HTML Web page to
any user. (System.Web.HttpRequestValidationException)
</p>
        <p>
Data Stored in the Application is not permanent. It is temporarily held in memory
on the server.
</p>
        <p>
The ASP.NET Application Life Cycle Page209
</p>
        <p>
Implemente HttpApplication events by adding a Global.asax file
</p>
        <p>
ASP.NET writes a cookie to the client’s machines to track their session. This cookie
is called ASP.NET_SessionId and contains a random 24-byte value. Requests submit this
cookie from the browser and ASP.NET maps the cookie’s value to the session on the
server.
</p>
        <p>
&lt;SessionState mode=”off”/&gt;  in web settings<br />
EnableSessionState=”False” in page 
<br />
&lt;SessionStte cookieless=”true” …/&gt; in web settings.<br />
Session_Start and Session_End events.<br />
Session State Mode: InProc, SateServer, SQLServer, Custom, Off
</p>
        <p>
Profile properties are persisted in a database on a per-user basis and not stored
in memory on a server.
</p>
        <p>
You can define a master page to work at the folder level within your site.<br />
Referencing Master Page Properties and Controls from Content Pages. P237
</p>
        <p>
Global Theme for all sites in your domain<br />
To apply a theme programmatically, set the page’s Theme property in the Page_PreInit
method.
</p>
        <p>
Web Parts are components of predefined fuctionality that can be embedded in a Web
page.<br />
Web Parts in ASP.NET require the ASP.NET personalization database (ASPNETDB) 
<br />
The display mode is set using the SupportedDisplayModes collection.<br />
Web Parts personalization relies on client-side cookies. It uses these cookies to
look up setting sin the ASPNETDB.<br />
Shared Personalization
</p>
        <p>
ScriptManager and ScriptManagerProxy<br />
UpdateMOde and ChildrenAsTrigger property of UpdatePanel<br />
AsyncPostBackTrigger of UpdatePanel
</p>
        <p>
AsyncPostBackError event of ScriptManager<br />
abortPOstBack method of the PageRequestManager class
</p>
        <p>
Page.ClientScript.RegisterClientScriptBlock; RegisterClientScript; RegisterONSubmitStatement
</p>
        <p>
Only script registered with the ScriptManager are available for use in partial-page
update scenarios. If you need your script in these scenarios you must resiger it with
the Script-Manager class.
</p>
        <p>
Creating own Client Callbacks<br />
Server-Side<br />
1. Implement the System.Web.UI,ICallbackEventHandler for your ASP.NET page.<br />
2. Implement the RaiseCallbackEvent method<br />
3. Implement the GetCallbackResult method<br />
In Page_Load<br />
1. Register the name of the client-side function by using Page.ClientScript.GetCallbackEventReference<br />
2. Define a function used by the client to call the server and register it by using
RegisterClientScriptBlock
</p>
        <p>
Loaded script: Call the notifyScriptLoaded method of the Sys.Application object to
tell the AJAX library once you have finished loading your script.
</p>
        <p>
AJAX Client-Side Life Cycle Events: 
<br />
Application: Init, load, unload, disposing<br />
PageRequestManager: initialiizeRequest, beginRequest, pageLoading, pageLoaded, endRequest
</p>
        <p>
When working with JavaScript files in the code editor, you can add a reference to
the AJAX Library. This will ensure your coding gets IntelliSense for the library.
This is similar to the using statement in c# and the imports statement in Visual Basic.
You embed this reference in a comment at the top of your .js file. The following shows
a example:<br />
/// &lt;reference anme=”MicrosoftAjax.js” /&gt;
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=6d7a160d-5727-4da5-b1c9-b30a2c311c6e" />
      </body>
      <title>70-562 part3</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,6d7a160d-5727-4da5-b1c9-b30a2c311c6e.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,6d7a160d-5727-4da5-b1c9-b30a2c311c6e.aspx</link>
      <pubDate>Fri, 02 Oct 2009 13:57:55 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;Page.ViewState&lt;/strong&gt; property provides a dictionary object for retaining
values between multiple requests for the ame page. The object is of the type &lt;strong&gt;StateBag&lt;/strong&gt;.&amp;nbsp;
Hidden field &lt;strong&gt;__ViewState. &lt;/strong&gt;The view state includes a message authentication
code (MAC). Or you can use ViewStateEncryptionMode property of the Page object to
protect the viewstate.
&lt;/p&gt;
&lt;p&gt;
Set to ControlEnableViewState to false to improve the performance on the large data
input form. (data state and control state)&lt;br&gt;
Control state allows you to store property value information that is specific to a
control. This state cannot be turned off and therefore should not be used in lieu
of view state. (Override OnInit, call Page.RegisterRequiresControlState method, override
the SaveControlState mthod)
&lt;/p&gt;
&lt;p&gt;
Hidden Fields control only store informaiton for a single page. Ti has no built-in
compression, encryption, hashing, or chunking. It only works with HTTP POST.
&lt;/p&gt;
&lt;p&gt;
Cookie’s Path and Domain propoerty. 
&lt;br&gt;
Response.Cookies[“Info”][“FirstName”].value = “Tony”; //store multiple values in a
Cookie
&lt;/p&gt;
&lt;p&gt;
Should validate the query string. Also you should always encode cookie or query string
values using Server.HtmlEncode before displaying the value in an HTML Web page to
any user. (System.Web.HttpRequestValidationException)
&lt;/p&gt;
&lt;p&gt;
Data Stored in the Application is not permanent. It is temporarily held in memory
on the server.
&lt;/p&gt;
&lt;p&gt;
The ASP.NET Application Life Cycle Page209
&lt;/p&gt;
&lt;p&gt;
Implemente HttpApplication events by adding a Global.asax file
&lt;/p&gt;
&lt;p&gt;
ASP.NET writes a cookie to the client’s machines to track their session. This cookie
is called ASP.NET_SessionId and contains a random 24-byte value. Requests submit this
cookie from the browser and ASP.NET maps the cookie’s value to the session on the
server.
&lt;/p&gt;
&lt;p&gt;
&amp;lt;SessionState mode=”off”/&amp;gt;&amp;nbsp; in web settings&lt;br&gt;
EnableSessionState=”False” in page 
&lt;br&gt;
&amp;lt;SessionStte cookieless=”true” …/&amp;gt; in web settings.&lt;br&gt;
Session_Start and Session_End events.&lt;br&gt;
Session State Mode: InProc, SateServer, SQLServer, Custom, Off
&lt;/p&gt;
&lt;p&gt;
Profile properties are persisted in a database on a per-user basis and not stored
in memory on a server.
&lt;/p&gt;
&lt;p&gt;
You can define a master page to work at the folder level within your site.&lt;br&gt;
Referencing Master Page Properties and Controls from Content Pages. P237
&lt;/p&gt;
&lt;p&gt;
Global Theme for all sites in your domain&lt;br&gt;
To apply a theme programmatically, set the page’s Theme property in the Page_PreInit
method.
&lt;/p&gt;
&lt;p&gt;
Web Parts are components of predefined fuctionality that can be embedded in a Web
page.&lt;br&gt;
Web Parts in ASP.NET require the ASP.NET personalization database (ASPNETDB) 
&lt;br&gt;
The display mode is set using the SupportedDisplayModes collection.&lt;br&gt;
Web Parts personalization relies on client-side cookies. It uses these cookies to
look up setting sin the ASPNETDB.&lt;br&gt;
Shared Personalization
&lt;/p&gt;
&lt;p&gt;
ScriptManager and ScriptManagerProxy&lt;br&gt;
UpdateMOde and ChildrenAsTrigger property of UpdatePanel&lt;br&gt;
AsyncPostBackTrigger of UpdatePanel
&lt;/p&gt;
&lt;p&gt;
AsyncPostBackError event of ScriptManager&lt;br&gt;
abortPOstBack method of the PageRequestManager class
&lt;/p&gt;
&lt;p&gt;
Page.ClientScript.RegisterClientScriptBlock; RegisterClientScript; RegisterONSubmitStatement
&lt;/p&gt;
&lt;p&gt;
Only script registered with the ScriptManager are available for use in partial-page
update scenarios. If you need your script in these scenarios you must resiger it with
the Script-Manager class.
&lt;/p&gt;
&lt;p&gt;
Creating own Client Callbacks&lt;br&gt;
Server-Side&lt;br&gt;
1. Implement the System.Web.UI,ICallbackEventHandler for your ASP.NET page.&lt;br&gt;
2. Implement the RaiseCallbackEvent method&lt;br&gt;
3. Implement the GetCallbackResult method&lt;br&gt;
In Page_Load&lt;br&gt;
1. Register the name of the client-side function by using Page.ClientScript.GetCallbackEventReference&lt;br&gt;
2. Define a function used by the client to call the server and register it by using
RegisterClientScriptBlock
&lt;/p&gt;
&lt;p&gt;
Loaded script: Call the notifyScriptLoaded method of the Sys.Application object to
tell the AJAX library once you have finished loading your script.
&lt;/p&gt;
&lt;p&gt;
AJAX Client-Side Life Cycle Events: 
&lt;br&gt;
Application: Init, load, unload, disposing&lt;br&gt;
PageRequestManager: initialiizeRequest, beginRequest, pageLoading, pageLoaded, endRequest
&lt;/p&gt;
&lt;p&gt;
When working with JavaScript files in the code editor, you can add a reference to
the AJAX Library. This will ensure your coding gets IntelliSense for the library.
This is similar to the using statement in c# and the imports statement in Visual Basic.
You embed this reference in a comment at the top of your .js file. The following shows
a example:&lt;br&gt;
/// &amp;lt;reference anme=”MicrosoftAjax.js” /&amp;gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=6d7a160d-5727-4da5-b1c9-b30a2c311c6e" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,6d7a160d-5727-4da5-b1c9-b30a2c311c6e.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=baec3e9f-9a3c-4e6a-9430-9a8d46765d40</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,baec3e9f-9a3c-4e6a-9430-9a8d46765d40.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,baec3e9f-9a3c-4e6a-9430-9a8d46765d40.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=baec3e9f-9a3c-4e6a-9430-9a8d46765d40</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/70562part2_F529/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/70562part2_F529/image_thumb.png" width="521" height="458" />
          </a>
        </p>
        <p>
View state is not stored by the server. It is saved into the page’s view state and
sent in the page’s response back to the user.
</p>
        <p>
Page Life Cycle Events: PreInit-&gt;Init-&gt;InitComplete-&gt;Load-&gt;Control(PostBack)
events-&gt;LoadComplete-&gt;PreRender-&gt;SaveStateComplete-&gt;Render-&gt;Unload
</p>
        <p>
HTML vs Web Server Control
</p>
        <p>
DIV tag’s InnerText and InnerHtml property
</p>
        <p>
Any postponed event (an event triggered by a user that does not cause an automatic
PostBack) executes before the actual event that caused the PostBack.   
<br />
AutoPostBack property
</p>
        <p>
Control c = FindControl(“lblMessage”);
</p>
        <p>
Use HttpUtility.HtmlEncode or the Server.HtmlEncode method to encode the untrusted
data prior to placing it the Text Property of the controls.
</p>
        <p>
Button control can be rendered as a submit button or a <strong>command button.</strong> Command
button is one of a set of buttons that work together as a group, such as a toolbar.
When clicked, Command event is called on the server. This event is passed an instance
of CommandEVentArgs as a parameter.
</p>
        <p>
Use the CheckBoxList control to create group of CheckBox controls. Same to RadioButtonList
</p>
        <p>
Label is rendered as a &lt;span&gt; tag.<br />
Literal control is not inherited from WebControl and mainly used to add text to the
output of the page dynamically (from server)<br />
Literal Mode Property: PassThrough, Encode, Transform
</p>
        <p>
The Image control does not have a Click event. In situations in which a click event
is necessary, you can use ImageButton or ImageMap instead. ImageMap allows you to
define regions or “hot spots” that cause a PostBack.<br />
If you set the HOtSpotMode on the HotSpot and the ImageMap, the HotSpot takes precedence.
</p>
        <p>
Use Calendar control to show the schedule. (DayRender event)
</p>
        <p>
Panel control generates a &lt;div&gt; element inside the browser.
</p>
        <p>
MultiView and View Controls are meant to work together.<br />
ACtiveViewIndex property and SetActiveView method. (Usually we use command buttons
for navigation)
</p>
        <p>
Xml control is used to display the contents of an XML document  with Extensible
Stylesheet Language(SXL) transform.
</p>
        <p>
Validators property of Page class. ASP.NET calls the Validate method automatically
after the page’s Load event handler method executes. You need to check the IsValid
property in every event handler to determine whether the code should run;<br />
EnableClientScript property and SetFocusOnError<br />
Set control’s CausesValidation to false to prevent Client-Side Validation.<br />
ValidationGroup
</p>
        <p>
Custom Client-Side Validation : function ClientFunctionName(source, arguments)<br />
Attach the client-side function to a CustomValidator by setting the ClientFunctionName
property of the CustomValidator control to the name of your validation function<br />
Custom Server-Side Validation: Override its ServerValidate event(source, args)
</p>
        <p>
Page Navigation: Client-side navigation;Cross-page posting;Client-side browser redirect;Server-side
transfer<br /><strong>Cross-page posting</strong>: Set PostBackUrl, Page, use PreviousPage property,
use PreviousPage.FindControl method or access strongly typed data directly.<br /><strong>Client-Side Browser Redirect</strong>: Use Response.Redirect (the redirect
is accomplished by sending a Http response code of (302) to the browser along with
the URL) (URL in address bar will change) (Can not access the PreviousPage property)<br />
Server-Side Transfer: Page.Server.Transfer method. It Tranfer the entire context of
a Web page over to another page (URL in address bar will not change) (You can access
the PreviousPage property)
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=baec3e9f-9a3c-4e6a-9430-9a8d46765d40" />
      </body>
      <title>70-562 part2</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,baec3e9f-9a3c-4e6a-9430-9a8d46765d40.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,baec3e9f-9a3c-4e6a-9430-9a8d46765d40.aspx</link>
      <pubDate>Wed, 30 Sep 2009 21:33:08 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/70562part2_F529/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/70562part2_F529/image_thumb.png" width="521" height="458"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
View state is not stored by the server. It is saved into the page’s view state and
sent in the page’s response back to the user.
&lt;/p&gt;
&lt;p&gt;
Page Life Cycle Events: PreInit-&amp;gt;Init-&amp;gt;InitComplete-&amp;gt;Load-&amp;gt;Control(PostBack)
events-&amp;gt;LoadComplete-&amp;gt;PreRender-&amp;gt;SaveStateComplete-&amp;gt;Render-&amp;gt;Unload
&lt;/p&gt;
&lt;p&gt;
HTML vs Web Server Control
&lt;/p&gt;
&lt;p&gt;
DIV tag’s InnerText and InnerHtml property
&lt;/p&gt;
&lt;p&gt;
Any postponed event (an event triggered by a user that does not cause an automatic
PostBack) executes before the actual event that caused the PostBack.&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
AutoPostBack property
&lt;/p&gt;
&lt;p&gt;
Control c = FindControl(“lblMessage”);
&lt;/p&gt;
&lt;p&gt;
Use HttpUtility.HtmlEncode or the Server.HtmlEncode method to encode the untrusted
data prior to placing it the Text Property of the controls.
&lt;/p&gt;
&lt;p&gt;
Button control can be rendered as a submit button or a &lt;strong&gt;command button.&lt;/strong&gt; Command
button is one of a set of buttons that work together as a group, such as a toolbar.
When clicked, Command event is called on the server. This event is passed an instance
of CommandEVentArgs as a parameter.
&lt;/p&gt;
&lt;p&gt;
Use the CheckBoxList control to create group of CheckBox controls. Same to RadioButtonList
&lt;/p&gt;
&lt;p&gt;
Label is rendered as a &amp;lt;span&amp;gt; tag.&lt;br&gt;
Literal control is not inherited from WebControl and mainly used to add text to the
output of the page dynamically (from server)&lt;br&gt;
Literal Mode Property: PassThrough, Encode, Transform
&lt;/p&gt;
&lt;p&gt;
The Image control does not have a Click event. In situations in which a click event
is necessary, you can use ImageButton or ImageMap instead. ImageMap allows you to
define regions or “hot spots” that cause a PostBack.&lt;br&gt;
If you set the HOtSpotMode on the HotSpot and the ImageMap, the HotSpot takes precedence.
&lt;/p&gt;
&lt;p&gt;
Use Calendar control to show the schedule. (DayRender event)
&lt;/p&gt;
&lt;p&gt;
Panel control generates a &amp;lt;div&amp;gt; element inside the browser.
&lt;/p&gt;
&lt;p&gt;
MultiView and View Controls are meant to work together.&lt;br&gt;
ACtiveViewIndex property and SetActiveView method. (Usually we use command buttons
for navigation)
&lt;/p&gt;
&lt;p&gt;
Xml control is used to display the contents of an XML document&amp;nbsp; with Extensible
Stylesheet Language(SXL) transform.
&lt;/p&gt;
&lt;p&gt;
Validators property of Page class. ASP.NET calls the Validate method automatically
after the page’s Load event handler method executes. You need to check the IsValid
property in every event handler to determine whether the code should run;&lt;br&gt;
EnableClientScript property and SetFocusOnError&lt;br&gt;
Set control’s CausesValidation to false to prevent Client-Side Validation.&lt;br&gt;
ValidationGroup
&lt;/p&gt;
&lt;p&gt;
Custom Client-Side Validation : function ClientFunctionName(source, arguments)&lt;br&gt;
Attach the client-side function to a CustomValidator by setting the ClientFunctionName
property of the CustomValidator control to the name of your validation function&lt;br&gt;
Custom Server-Side Validation: Override its ServerValidate event(source, args)
&lt;/p&gt;
&lt;p&gt;
Page Navigation: Client-side navigation;Cross-page posting;Client-side browser redirect;Server-side
transfer&lt;br&gt;
&lt;strong&gt;Cross-page posting&lt;/strong&gt;: Set PostBackUrl, Page, use PreviousPage property,
use PreviousPage.FindControl method or access strongly typed data directly.&lt;br&gt;
&lt;strong&gt;Client-Side Browser Redirect&lt;/strong&gt;: Use Response.Redirect (the redirect
is accomplished by sending a Http response code of (302) to the browser along with
the URL) (URL in address bar will change) (Can not access the PreviousPage property)&lt;br&gt;
Server-Side Transfer: Page.Server.Transfer method. It Tranfer the entire context of
a Web page over to another page (URL in address bar will not change) (You can access
the PreviousPage property)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=baec3e9f-9a3c-4e6a-9430-9a8d46765d40" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,baec3e9f-9a3c-4e6a-9430-9a8d46765d40.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=57b1f88a-db6e-4662-b5c6-582ba2051795</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,57b1f88a-db6e-4662-b5c6-582ba2051795.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,57b1f88a-db6e-4662-b5c6-582ba2051795.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=57b1f88a-db6e-4662-b5c6-582ba2051795</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
HTTP Verbs: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, DEBUG<br />
                  
LOCK AND UNLOCK (ONLY WITH DAV)
</p>
        <p>
DAV: Disributed Authoring and Versioning. It is a set of extensions to HTTP/1.1
</p>
        <p>
HTTP/1.1 200 ok   200 is the status code.<br />
1xx: Informational  2xx: Success   3xx: Redirect Command  
4xx: Client Error 5xx: Server Error
</p>
        <p>
Get and Post: Get append the form data to the URL as part of the query string. Post
put the form data into the message body of the request.
</p>
        <p>
Assemblies in the Bin folder are automatically referenced in web application.
</p>
        <p>
ASPX page = Page directives + Code + Page Layout 
</p>
        <p>
Dynamically compilation and pre-compilation (only in 2008)
</p>
        <p>
FTP passive and active mode. (passive is more firewall friendly)
</p>
        <p>
.SUO file: User option file. 
<br />
It is best to keep the solution files in an independent folder.
</p>
        <p>
Root Default Web.config file is located in the same directory as the Machine.config
file.
</p>
        <p>
WSAT: Web Site Administration Tool 
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=57b1f88a-db6e-4662-b5c6-582ba2051795" />
      </body>
      <title>70-562 part1</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,57b1f88a-db6e-4662-b5c6-582ba2051795.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,57b1f88a-db6e-4662-b5c6-582ba2051795.aspx</link>
      <pubDate>Wed, 30 Sep 2009 03:08:37 GMT</pubDate>
      <description>&lt;p&gt;
HTTP Verbs: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, DEBUG&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;&amp;nbsp;&amp;nbsp;
LOCK AND UNLOCK (ONLY WITH DAV)
&lt;/p&gt;
&lt;p&gt;
DAV: Disributed Authoring and Versioning. It is a set of extensions to HTTP/1.1
&lt;/p&gt;
&lt;p&gt;
HTTP/1.1 200 ok&amp;nbsp;&amp;nbsp; 200 is the status code.&lt;br&gt;
1xx: Informational&amp;nbsp; 2xx: Success&amp;nbsp;&amp;nbsp; 3xx: Redirect Command&amp;nbsp;&amp;nbsp;
4xx: Client Error 5xx: Server Error
&lt;/p&gt;
&lt;p&gt;
Get and Post: Get append the form data to the URL as part of the query string. Post
put the form data into the message body of the request.
&lt;/p&gt;
&lt;p&gt;
Assemblies in the Bin folder are automatically referenced in web application.
&lt;/p&gt;
&lt;p&gt;
ASPX page = Page directives + Code + Page Layout 
&lt;/p&gt;
&lt;p&gt;
Dynamically compilation and pre-compilation (only in 2008)
&lt;/p&gt;
&lt;p&gt;
FTP passive and active mode. (passive is more firewall friendly)
&lt;/p&gt;
&lt;p&gt;
.SUO file: User option file. 
&lt;br&gt;
It is best to keep the solution files in an independent folder.
&lt;/p&gt;
&lt;p&gt;
Root Default Web.config file is located in the same directory as the Machine.config
file.
&lt;/p&gt;
&lt;p&gt;
WSAT: Web Site Administration Tool 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=57b1f88a-db6e-4662-b5c6-582ba2051795" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,57b1f88a-db6e-4662-b5c6-582ba2051795.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=c0a90b09-719f-4114-9f9e-95fbae6cbe54</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,c0a90b09-719f-4114-9f9e-95fbae6cbe54.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,c0a90b09-719f-4114-9f9e-95fbae6cbe54.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c0a90b09-719f-4114-9f9e-95fbae6cbe54</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
PrintDocument.BeginPrint event, set the position of the streamToPrint.BaseStream property
to 0.
</p>
        <p>
chkIsManager.DataBindings.Add(“Checked”, ds, “Users.IsManager);
</p>
        <p>
DataRowVersion.Original
</p>
        <p>
Thread.Enter and Exit to lock object for reading and writing.
</p>
        <p>
SuspendLayout and ResumeLayout <a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx</a></p>
        <p>
XmlReader is more timeefficient than XmlDocument and Linq to XML
</p>
        <p>
SafePrinting (PrintingPermissionLevel enumerations)
</p>
        <p>
Call the endInvoke method in callback method
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=c0a90b09-719f-4114-9f9e-95fbae6cbe54" />
      </body>
      <title>70-505 Part9</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,c0a90b09-719f-4114-9f9e-95fbae6cbe54.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,c0a90b09-719f-4114-9f9e-95fbae6cbe54.aspx</link>
      <pubDate>Sat, 26 Sep 2009 20:12:28 GMT</pubDate>
      <description>&lt;p&gt;
PrintDocument.BeginPrint event, set the position of the streamToPrint.BaseStream property
to 0.
&lt;/p&gt;
&lt;p&gt;
chkIsManager.DataBindings.Add(“Checked”, ds, “Users.IsManager);
&lt;/p&gt;
&lt;p&gt;
DataRowVersion.Original
&lt;/p&gt;
&lt;p&gt;
Thread.Enter and Exit to lock object for reading and writing.
&lt;/p&gt;
&lt;p&gt;
SuspendLayout and ResumeLayout &lt;a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
XmlReader is more timeefficient than XmlDocument and Linq to XML
&lt;/p&gt;
&lt;p&gt;
SafePrinting (PrintingPermissionLevel enumerations)
&lt;/p&gt;
&lt;p&gt;
Call the endInvoke method in callback method
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=c0a90b09-719f-4114-9f9e-95fbae6cbe54" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,c0a90b09-719f-4114-9f9e-95fbae6cbe54.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=469cef1b-6073-4d2c-a094-2bc87a8b39fb</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,469cef1b-6073-4d2c-a094-2bc87a8b39fb.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,469cef1b-6073-4d2c-a094-2bc87a8b39fb.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=469cef1b-6073-4d2c-a094-2bc87a8b39fb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Load assembly on demand <a title="http://msdn.microsoft.com/en-us/library/ms228997.aspx" href="http://msdn.microsoft.com/en-us/library/ms228997.aspx">http://msdn.microsoft.com/en-us/library/ms228997.aspx</a><br />
1. Mark each dependency in Certkiller App1.exe.manifest as optional<br />
2. Create an event handler for the AppDomain.ResourceResolve event named ResolveAssembly<br />
3. In the ResolveAssembly event hander, call ApplicationDeployment.DowloadFiles and
pass in the name of the assembly you want.
</p>
        <p>
Databinding master-detail datagrid 
<br />
Set the DataMember property of the child DataGridView to the name of the data relation.
</p>
        <p>
Use SystemEvents.UserPreferenceChanged to deal with accessibility change event
</p>
        <p>
          <strong>ToolStripControlHost</strong>
          <a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx">http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=469cef1b-6073-4d2c-a094-2bc87a8b39fb" />
      </body>
      <title>70-505 part8</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,469cef1b-6073-4d2c-a094-2bc87a8b39fb.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,469cef1b-6073-4d2c-a094-2bc87a8b39fb.aspx</link>
      <pubDate>Sat, 26 Sep 2009 04:37:50 GMT</pubDate>
      <description>&lt;p&gt;
Load assembly on demand &lt;a title="http://msdn.microsoft.com/en-us/library/ms228997.aspx" href="http://msdn.microsoft.com/en-us/library/ms228997.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms228997.aspx&lt;/a&gt;
&lt;br&gt;
1. Mark each dependency in Certkiller App1.exe.manifest as optional&lt;br&gt;
2. Create an event handler for the AppDomain.ResourceResolve event named ResolveAssembly&lt;br&gt;
3. In the ResolveAssembly event hander, call ApplicationDeployment.DowloadFiles and
pass in the name of the assembly you want.
&lt;/p&gt;
&lt;p&gt;
Databinding master-detail datagrid 
&lt;br&gt;
Set the DataMember property of the child DataGridView to the name of the data relation.
&lt;/p&gt;
&lt;p&gt;
Use SystemEvents.UserPreferenceChanged to deal with accessibility change event
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;ToolStripControlHost&lt;/strong&gt; &lt;a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripcontrolhost.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=469cef1b-6073-4d2c-a094-2bc87a8b39fb" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,469cef1b-6073-4d2c-a094-2bc87a8b39fb.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=a51946e5-5762-461f-af7d-0b152c9c5750</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,a51946e5-5762-461f-af7d-0b152c9c5750.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,a51946e5-5762-461f-af7d-0b152c9c5750.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a51946e5-5762-461f-af7d-0b152c9c5750</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
AccessibleStates 
<br /><a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessiblestates.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessiblestates.aspx">http://msdn.microsoft.com/en-us/library/system.windows.forms.accessiblestates.aspx</a><br /><a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessibleobject.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessibleobject.aspx">http://msdn.microsoft.com/en-us/library/system.windows.forms.accessibleobject.aspx</a></p>
        <p>
          <strong>Transitive</strong> property of installation package
</p>
        <p>
Set the <strong>InstallerClass</strong> property of your custom action to False when
you want to add a standard Console application at the end of the installation process
</p>
        <p>
          <strong>SqlDependency</strong> is ideal for caching scenarios, where your ASP.NET
application or middle-tier service needs to keep certain information cached in memory.
SqlDependency allows you to receive notifications when the original data in the database
changes so that the cache can be refreshed. 
</p>
        <p>
To set up a dependency, you need to associate a SqlDependency object to one or more <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx">SqlCommand</a> objects.
To receive notifications, you need to subscribe to the <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.onchange.aspx">OnChange</a> event.
For more information about the requirements for creating queries for notifications,
see "Creating a Query for Notification" in SQL Server Books Online 
</p>
        <p>
  
</p>
        <p>
Thread.Begin(End)CriticalRegion: Notifies a host that execution is about to enter
a region of code in which the effects of a thread abort or unhandled exception might
jeopardize other tasks in the application domain. 
</p>
        <p>
  
</p>
        <p>
Deploy the COM component by using ClickOnce <a title="http://msdn.microsoft.com/en-us/library/ms165432%28VS.80%29.aspx" href="http://msdn.microsoft.com/en-us/library/ms165432%28VS.80%29.aspx">http://msdn.microsoft.com/en-us/library/ms165432%28VS.80%29.aspx</a></p>
        <p>
Application.Settings <a title="http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx" href="http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx">http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx</a></p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=a51946e5-5762-461f-af7d-0b152c9c5750" />
      </body>
      <title>70-505 part7</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,a51946e5-5762-461f-af7d-0b152c9c5750.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,a51946e5-5762-461f-af7d-0b152c9c5750.aspx</link>
      <pubDate>Fri, 25 Sep 2009 21:44:08 GMT</pubDate>
      <description>&lt;p&gt;
AccessibleStates 
&lt;br&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessiblestates.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessiblestates.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.windows.forms.accessiblestates.aspx&lt;/a&gt;
&lt;br&gt;
&lt;a title="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessibleobject.aspx" href="http://msdn.microsoft.com/en-us/library/system.windows.forms.accessibleobject.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.windows.forms.accessibleobject.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Transitive&lt;/strong&gt; property of installation package
&lt;/p&gt;
&lt;p&gt;
Set the &lt;strong&gt;InstallerClass&lt;/strong&gt; property of your custom action to False when
you want to add a standard Console application at the end of the installation process
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;SqlDependency&lt;/strong&gt; is ideal for caching scenarios, where your ASP.NET
application or middle-tier service needs to keep certain information cached in memory.
SqlDependency allows you to receive notifications when the original data in the database
changes so that the cache can be refreshed. 
&lt;p&gt;
To set up a dependency, you need to associate a SqlDependency object to one or more &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx"&gt;SqlCommand&lt;/a&gt; objects.
To receive notifications, you need to subscribe to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.onchange.aspx"&gt;OnChange&lt;/a&gt; event.
For more information about the requirements for creating queries for notifications,
see "Creating a Query for Notification" in SQL Server Books Online 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Thread.Begin(End)CriticalRegion: Notifies a host that execution is about to enter
a region of code in which the effects of a thread abort or unhandled exception might
jeopardize other tasks in the application domain. 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Deploy the COM component by using ClickOnce &lt;a title="http://msdn.microsoft.com/en-us/library/ms165432%28VS.80%29.aspx" href="http://msdn.microsoft.com/en-us/library/ms165432%28VS.80%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms165432%28VS.80%29.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Application.Settings &lt;a title="http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx" href="http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx"&gt;http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=a51946e5-5762-461f-af7d-0b152c9c5750" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,a51946e5-5762-461f-af7d-0b152c9c5750.aspx</comments>
      <category>DotNet</category>
    </item>
    <item>
      <trackback:ping>http://blog.ilovedoudou.com/Trackback.aspx?guid=274bf616-4bd9-4d81-99da-16ada2b4e1ba</trackback:ping>
      <pingback:server>http://blog.ilovedoudou.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.ilovedoudou.com/PermaLink,guid,274bf616-4bd9-4d81-99da-16ada2b4e1ba.aspx</pingback:target>
      <dc:creator>Kevin Mocha</dc:creator>
      <wfw:comment>http://blog.ilovedoudou.com/CommentView,guid,274bf616-4bd9-4d81-99da-16ada2b4e1ba.aspx</wfw:comment>
      <wfw:commentRss>http://blog.ilovedoudou.com/SyndicationService.asmx/GetEntryCommentsRss?guid=274bf616-4bd9-4d81-99da-16ada2b4e1ba</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Transaction Scope
</p>
        <p>
Enumerate SQL Data sources. 
</p>
        <p>
CommandBehavior.SequentialAccess as a parameter for ExecuteReader method to support
stream reading.
</p>
        <p>
check Nested relation between two tables to make XML serialization results nested 
</p>
        <p>
PrintControllerWithStatusDialog
</p>
        <p>
QueryPageSettings event
</p>
        <p>
PrintDocument allows you to override the OnPrintPage method that can add a water mark
on each page. The PrintController class will allow you to control the printing process
but cannot force secure watermarks.
</p>
        <p>
Basically, Assert gives some additional rights to untrusted code, while Demand requires
that everyone in the call stack must have the required permissions.
</p>
        <p>
CurrentUICulture only identifies the culture to be used by a resource manager. 
</p>
        <p>
The WorkerReportsProgress property should be set when ReportProgress is wanted to
report the progress.
</p>
        <p>
Event-based Asynchronous Pattern <a title="http://msdn.microsoft.com/en-us/library/wewwczdw.aspx" href="http://msdn.microsoft.com/en-us/library/wewwczdw.aspx">http://msdn.microsoft.com/en-us/library/wewwczdw.aspx</a><br />
A class that supports the Event-based Asynchronous Pattern will have one or more methods
named MethodNameAsync. 
<br />
These methods may mirror synchronous versions, which perform the same operation on
the current thread. The class 
<br />
may also have a MethodNameCompleted event and it may have a MethodNameAsyncCancel
(or simply CancelAsync) method.
</p>
        <p>
The UserPaint flag shows that the control paints itself than having the operating
system performs the job. If the flag is not set, the OnPaint method is not called.
</p>
        <p>
ClickOnce Dynamic loading assembly: You should handle the AssemblyResolve event of
the AppDomain class and call the DownLoadFileGroup method of the ApplicationDeployment
class. 
</p>
        <p>
Mage.exe is used to change the GradeBook.application settings. It also helps to manage
a published application.
</p>
        <p>
x86 setting allows a package to be installed on 32-bit and 64-bit computer.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=274bf616-4bd9-4d81-99da-16ada2b4e1ba" />
      </body>
      <title>70-505 part6</title>
      <guid isPermaLink="false">http://blog.ilovedoudou.com/PermaLink,guid,274bf616-4bd9-4d81-99da-16ada2b4e1ba.aspx</guid>
      <link>http://blog.ilovedoudou.com/PermaLink,guid,274bf616-4bd9-4d81-99da-16ada2b4e1ba.aspx</link>
      <pubDate>Thu, 24 Sep 2009 21:11:15 GMT</pubDate>
      <description>&lt;p&gt;
Transaction Scope
&lt;/p&gt;
&lt;p&gt;
Enumerate SQL Data sources. 
&lt;/p&gt;
&lt;p&gt;
CommandBehavior.SequentialAccess as a parameter for ExecuteReader method to support
stream reading.
&lt;/p&gt;
&lt;p&gt;
check Nested relation between two tables to make XML serialization results nested 
&lt;/p&gt;
&lt;p&gt;
PrintControllerWithStatusDialog
&lt;/p&gt;
&lt;p&gt;
QueryPageSettings event
&lt;/p&gt;
&lt;p&gt;
PrintDocument allows you to override the OnPrintPage method that can add a water mark
on each page. The PrintController class will allow you to control the printing process
but cannot force secure watermarks.
&lt;/p&gt;
&lt;p&gt;
Basically, Assert gives some additional rights to untrusted code, while Demand requires
that everyone in the call stack must have the required permissions.
&lt;/p&gt;
&lt;p&gt;
CurrentUICulture only identifies the culture to be used by a resource manager. 
&lt;/p&gt;
&lt;p&gt;
The WorkerReportsProgress property should be set when ReportProgress is wanted to
report the progress.
&lt;/p&gt;
&lt;p&gt;
Event-based Asynchronous Pattern &lt;a title="http://msdn.microsoft.com/en-us/library/wewwczdw.aspx" href="http://msdn.microsoft.com/en-us/library/wewwczdw.aspx"&gt;http://msdn.microsoft.com/en-us/library/wewwczdw.aspx&lt;/a&gt;
&lt;br&gt;
A class that supports the Event-based Asynchronous Pattern will have one or more methods
named MethodNameAsync. 
&lt;br&gt;
These methods may mirror synchronous versions, which perform the same operation on
the current thread. The class 
&lt;br&gt;
may also have a MethodNameCompleted event and it may have a MethodNameAsyncCancel
(or simply CancelAsync) method.
&lt;/p&gt;
&lt;p&gt;
The UserPaint flag shows that the control paints itself than having the operating
system performs the job. If the flag is not set, the OnPaint method is not called.
&lt;/p&gt;
&lt;p&gt;
ClickOnce Dynamic loading assembly: You should handle the AssemblyResolve event of
the AppDomain class and call the DownLoadFileGroup method of the ApplicationDeployment
class. 
&lt;/p&gt;
&lt;p&gt;
Mage.exe is used to change the GradeBook.application settings. It also helps to manage
a published application.
&lt;/p&gt;
&lt;p&gt;
x86 setting allows a package to be installed on 32-bit and 64-bit computer.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=274bf616-4bd9-4d81-99da-16ada2b4e1ba" /&gt;</description>
      <comments>http://blog.ilovedoudou.com/CommentView,guid,274bf616-4bd9-4d81-99da-16ada2b4e1ba.aspx</comments>
      <category>DotNet</category>
    </item>
  </channel>
</rss>