<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jennal's Blog &#187; .net</title>
	<atom:link href="http://jennal.cn/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://jennal.cn</link>
	<description>Jennal的技术博客</description>
	<lastBuildDate>Tue, 06 Mar 2012 00:51:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>王翔的《设计模式》读书笔记</title>
		<link>http://jennal.cn/2009/11/18/%e7%8e%8b%e7%bf%94%e7%9a%84%e3%80%8a%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e3%80%8b%e8%af%bb%e4%b9%a6%e7%ac%94%e8%ae%b0/</link>
		<comments>http://jennal.cn/2009/11/18/%e7%8e%8b%e7%bf%94%e7%9a%84%e3%80%8a%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e3%80%8b%e8%af%bb%e4%b9%a6%e7%ac%94%e8%ae%b0/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 04:37:41 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[依赖注入]]></category>
		<category><![CDATA[设计模式]]></category>
		<category><![CDATA[读书笔记]]></category>

		<guid isPermaLink="false">http://jennal.cn/2009/11/18/%e7%8e%8b%e7%bf%94%e7%9a%84%e3%80%8a%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e3%80%8b%e8%af%bb%e4%b9%a6%e7%ac%94%e8%ae%b0/</guid>
		<description><![CDATA[今天读王翔的《设计模式 &#8211; 基于C#的工程化实现及扩展》，刚把第一章读完。作为一个C#初学者和工作者，发现了55页，也就是第一章的最后一段关于依赖注入的实例代码中有一个很明显的错误。本来想直接联系作者的，可是实在找不到他的联系方式，就发在自己博客上了。如果同样读过这本书的人能看到，不胜荣幸。
代码如下：

&#91;AttributeUsage&#40;AttributeTargets.Class&#41;, AllowMultiple=true&#93;
sealed class DecoratorAttribute : Attribute
&#123;
    public readonly object Injector;
    private Type type;
&#160;
    public DecoratorAttribute&#40;Type type&#41;
    &#123;
        if &#40;type == null&#41; throw new ArgumentNullException&#40;&#34;type&#34;&#41;;
        this.type = type;
 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F07%2F09%2F%25E6%25B5%25AA%25E6%25BD%25AE%25E4%25B9%258B%25E5%25B7%2585%25E7%25AC%25AC%25E5%258D%2581%25E5%2585%25AD%25E7%25AB%25A0-%25E5%258D%25B0%25E9%2592%259E%25E6%259C%25BA%25E2%2580%2594%25E2%2580%2594%25E6%259C%2580%25E4%25BD%25B3%25E7%259A%2584%25E5%2595%2586%25E4%25B8%259A%25E6%25A8%25A1%25E5%25BC%258F%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">浪潮之巅第十六章 印钞机——最佳的商业模式</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F02%2Fjavascript%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0-%25E7%25B1%25BB%25E7%259A%2584%25E7%25BB%25A7%25E6%2589%25BF%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Javascript学习笔记–类的继承</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F07%2F25%2Fweb-designer-developer-should-know-15-sites%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]Web 设计与开发者必须知道的 15 个站点</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2010%2F01%2F30%2F%25E3%2580%258A%25E5%258A%259F%25E5%25A4%25AB%25E4%25B9%258B%25E7%258E%258B%25E3%2580%258B%25E8%25A7%2582%25E5%2590%258E%25E6%2584%259F%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">《功夫之王》观后感</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>今天读王翔的《设计模式 &#8211; 基于C#的工程化实现及扩展》，刚把第一章读完。作为一个C#初学者和工作者，发现了55页，也就是第一章的最后一段关于依赖注入的实例代码中有一个很明显的错误。本来想直接联系作者的，可是实在找不到他的联系方式，就发在自己博客上了。如果同样读过这本书的人能看到，不胜荣幸。</p>
<p>代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>AttributeUsage<span style="color: #009900;">&#40;</span>AttributeTargets.<span style="color: #000000; font-weight: bold;">Class</span><span style="color: #009900;">&#41;</span>, AllowMultiple<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#93;</span>
sealed <span style="color: #000000; font-weight: bold;">class</span> DecoratorAttribute <span style="color: #339933;">:</span> <span style="color: #003399;">Attribute</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> readonly object Injector<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Type type<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> DecoratorAttribute<span style="color: #009900;">&#40;</span>Type type<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>type <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ArgumentNullException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">type</span> <span style="color: #339933;">=</span> type<span style="color: #339933;">;</span>
        Injector <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Assembler<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">Create</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Type Type <span style="color: #009900;">&#123;</span> get <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">type</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> AttributeHelper
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> T Injector<span style="color: #009900;">&#40;</span>object target<span style="color: #009900;">&#41;</span>
        where T <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">class</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>target <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> ArgumentNullException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;target&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Type targetType <span style="color: #339933;">=</span> target.<span style="color: #006633;">GetType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        object<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> attributes <span style="color: #339933;">=</span> targetType.<span style="color: #006633;">GetCustomAttributes</span><span style="color: #009900;">&#40;</span>
            typeof<span style="color: #009900;">&#40;</span>DecoratorAttribute<span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>attributes <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>attributes.<span style="color: #006633;">Length</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">foreach</span> <span style="color: #009900;">&#40;</span>DecoratorAttribute attribute in
            <span style="color: #009900;">&#40;</span>DecoratorAttribute <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>attributes<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>attribute.<span style="color: #006633;">Type</span> <span style="color: #339933;">==</span> typeof<span style="color: #009900;">&#40;</span>T<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>T<span style="color: #009900;">&#41;</span>attribute.<span style="color: #006633;">Injector</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#91;</span>Decorator<span style="color: #009900;">&#40;</span>typeof<span style="color: #009900;">&#40;</span>ITimeProvider<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>
<span style="color: #000000; font-weight: bold;">class</span> Client
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> GetYear<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        ITimeProvider provider <span style="color: #339933;">=</span>
            AttributeHelper.<span style="color: #006633;">Injector</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> provider.<span style="color: #006633;">CurrentDate</span>.<span style="color: #006633;">Year</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>这段代码是依赖注入。使用Attribute把外部对接口的实现注入到类中。通过修改Attribute来改变依赖。<br />
其中第29行和第35行中，有一个明显的错误。<br />
先从第35行说起</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>Decorator<span style="color: #009900;">&#40;</span>typeof<span style="color: #009900;">&#40;</span>ITimeProvider<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span></pre></div></div>

<p>这行代码说明要注入ITimeProvider类型，但是我们知道接口是不能被直接实例化的。所以这里的ITimeProvider应该改成TimeProvider。<br />
但是这个时候第35行的条件判断就出现问题了，因为我们要得到的是ITimeProvider，而Decorator给的参数是TimeProvider，这两个类型是不会相等的。<br />
这个时候我们还必须修改第35行的代码为</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>attribute.<span style="color: #006633;">Type</span>.<span style="color: #006633;">GetInterfaces</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">Contains</span><span style="color: #009900;">&#40;</span>typeof<span style="color: #009900;">&#40;</span>T<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>通过寻找实现接口的实例，才能够真正找到我们要的Decorator。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F07%2F09%2F%25E6%25B5%25AA%25E6%25BD%25AE%25E4%25B9%258B%25E5%25B7%2585%25E7%25AC%25AC%25E5%258D%2581%25E5%2585%25AD%25E7%25AB%25A0-%25E5%258D%25B0%25E9%2592%259E%25E6%259C%25BA%25E2%2580%2594%25E2%2580%2594%25E6%259C%2580%25E4%25BD%25B3%25E7%259A%2584%25E5%2595%2586%25E4%25B8%259A%25E6%25A8%25A1%25E5%25BC%258F%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">浪潮之巅第十六章 印钞机——最佳的商业模式</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F02%2Fjavascript%25E5%25AD%25A6%25E4%25B9%25A0%25E7%25AC%2594%25E8%25AE%25B0-%25E7%25B1%25BB%25E7%259A%2584%25E7%25BB%25A7%25E6%2589%25BF%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Javascript学习笔记–类的继承</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F07%2F25%2Fweb-designer-developer-should-know-15-sites%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]Web 设计与开发者必须知道的 15 个站点</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2010%2F01%2F30%2F%25E3%2580%258A%25E5%258A%259F%25E5%25A4%25AB%25E4%25B9%258B%25E7%258E%258B%25E3%2580%258B%25E8%25A7%2582%25E5%2590%258E%25E6%2584%259F%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F11%2F18%2F%25E7%258E%258B%25E7%25BF%2594%25E7%259A%2584%25E3%2580%258A%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25A8%25A1%25E5%25BC%258F%25E3%2580%258B%25E8%25AF%25BB%25E4%25B9%25A6%25E7%25AC%2594%25E8%25AE%25B0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">《功夫之王》观后感</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/11/18/%e7%8e%8b%e7%bf%94%e7%9a%84%e3%80%8a%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e3%80%8b%e8%af%bb%e4%b9%a6%e7%ac%94%e8%ae%b0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>关于C#反射很棒的文章</title>
		<link>http://jennal.cn/2009/09/28/%e5%85%b3%e4%ba%8ec%e5%8f%8d%e5%b0%84%e5%be%88%e6%a3%92%e7%9a%84%e6%96%87%e7%ab%a0/</link>
		<comments>http://jennal.cn/2009/09/28/%e5%85%b3%e4%ba%8ec%e5%8f%8d%e5%b0%84%e5%be%88%e6%a3%92%e7%9a%84%e6%96%87%e7%ab%a0/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 01:18:28 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[reflect]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=241</guid>
		<description><![CDATA[中文翻译：http://www.infoq.com/cn/articles/expression-compiler
英文原文：http://www.infoq.com/articles/expression-compiler
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#的疑问</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>中文翻译：<a href="http://www.infoq.com/cn/articles/expression-compiler">http://www.infoq.com/cn/articles/expression-compiler</a></p>
<p>英文原文：<a href="http://www.infoq.com/articles/expression-compiler">http://www.infoq.com/articles/expression-compiler</a></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#的疑问</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/09/28/%e5%85%b3%e4%ba%8ec%e5%8f%8d%e5%b0%84%e5%be%88%e6%a3%92%e7%9a%84%e6%96%87%e7%ab%a0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#动态加载DLL</title>
		<link>http://jennal.cn/2009/09/24/c%e5%8a%a8%e6%80%81%e5%8a%a0%e8%bd%bddll/</link>
		<comments>http://jennal.cn/2009/09/24/c%e5%8a%a8%e6%80%81%e5%8a%a0%e8%bd%bddll/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 09:20:33 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[reflect]]></category>
		<category><![CDATA[动态加载]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=239</guid>
		<description><![CDATA[利用反射进行动态加载和调用.
Assembly ass=Assembly.LoadFrom(DllPath); //利用dll的路径加载,同时将此程序集所依赖的程序集加载进来,需后辍名.dll
Assembly.LoadFile 只加载指定文件，并不会自动加载依赖程序集.Assmbly.Load无需后辍名
加载dll后,需要使用dll中某类.
Type type=ass.GetType(“TypeName”);//利用类型的命名空间和名称获得类型
需要实例化类型,才可以使用,参数可以人为的指定,也可以无参数,静态实例可以省略
Object obj = Activator.CreateInstance(type,params[]);//利用指定的参数实例话类型
调用类型中的某个方法:
需要首先得到此方法
MethodInfo mi=type.GetMethod(“MehtodName”);//通过方法名称获得方法
然后对方法进行调用,多态性利用参数进行控制
mi.Invoke(obj,params[]);//根据参数直线方法,返回值就是原方法的返回值
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于C#反射很棒的文章</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>利用反射进行动态加载和调用.<br />
Assembly ass=Assembly.LoadFrom(DllPath); //利用dll的路径加载,同时将此程序集所依赖的程序集加载进来,需后辍名.dll<br />
Assembly.LoadFile 只加载指定文件，并不会自动加载依赖程序集.Assmbly.Load无需后辍名</p>
<p>加载dll后,需要使用dll中某类.<br />
Type type=ass.GetType(“TypeName”);//利用类型的命名空间和名称获得类型</p>
<p>需要实例化类型,才可以使用,参数可以人为的指定,也可以无参数,静态实例可以省略<br />
Object obj = Activator.CreateInstance(type,params[]);//利用指定的参数实例话类型</p>
<p>调用类型中的某个方法:<br />
需要首先得到此方法<br />
MethodInfo mi=type.GetMethod(“MehtodName”);//通过方法名称获得方法</p>
<p>然后对方法进行调用,多态性利用参数进行控制<br />
mi.Invoke(obj,params[]);//根据参数直线方法,返回值就是原方法的返回值</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于C#反射很棒的文章</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/09/24/c%e5%8a%a8%e6%80%81%e5%8a%a0%e8%bd%bddll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Switching Versions of the ASP.Net Framework &#8211; The Fast Way</title>
		<link>http://jennal.cn/2009/04/15/switching-versions-of-the-aspnet-framework-the-fast-way/</link>
		<comments>http://jennal.cn/2009/04/15/switching-versions-of-the-aspnet-framework-the-fast-way/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 09:27:42 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=154</guid>
		<description><![CDATA[By Scott Forsyth
November 28, 2003
When ASP.NET v1.1             was released, it became my project to find the best way to support this for our             client base at ORCS Web, Inc. We needed [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]IIS ASP.NET 1.1与2.0共存</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">ASPNET_regiis.exe Tool, Setting the Default Version Without Forcing an Upgrade on All Sites</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>By Scott Forsyth<br />
November 28, 2003</p>
<p><span style="font-size: 10pt;">When ASP.NET v1.1             was released, it became my project to find the best way to support this for our             client base at ORCS Web, Inc. We needed to be able to switch versions of the Framework             per site as smoothly as possible. Requiring everyone to move to version 1.1 wouldn&#8217;t             work and leaving everyone on version 1.0 wouldn&#8217;t work either, so we had to have             a way to pick and choose and to make the switch without interrupting other sites             on the same server. </span></p>
<p><span style="font-size: 10pt;"><strong>Is this for you?</strong> </span></p>
<p><span style="font-size: 10pt;">Before I go any further, I should mention the reasons             why this applies to the average developer as well as the system administrator. Currently             there are two released versions of ASP.NET but there are already multiple alpha             and beta versions and there will continue to be more. To be able to quickly switch             between versions with just a couple clicks and keystrokes makes development and             testing against multiple frameworks easy. Granted, aspnet_regiis.exe will accomplish             this as I’ll mention below, but it can take over 30 seconds. Imagine being able             to immediately switch between Version 1.0, 1.1 and         2.0 (v2.0 is in Alpha at the             time of this writing) without setting up multiple sites in IIS. If this interests             you, read on because this doesn&#8217;t just apply to a system administrator. </span></p>
<p><span style="font-size: 10pt;"><strong>Objectives</strong> </span></p>
<p><span style="font-size: 10pt;">My 4 objectives were:<br />
1) To be able to update a single site to the new framework<br />
2) To be able to revert back if desired<br />
3) To have an easy way for anyone on our team to be able to do it                 consistently and quickly<br />
4) To do this without affecting the other sites on the same server<br />
</span></p>
<p><span style="font-size: 10pt;"><strong>Stating the Obvious</strong> </span></p>
<p><span style="font-size: 10pt;">The most obvious way to do this was to use aspnet_regiis.exe supplied with ASP.NET. To use this method I would run &#8220;C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -s W3SVC/50/ROOT&#8221;. This would update the Version of the framework for the site with ID 50 and not update the other sites on this server. It has the flexibility required to set this for the whole server, per site or even per sub-folder. The problem I immediately ran into was that both Internet Information Server (IIS) service and Session State would reset, causing every site on the server to be down for up to 2 minutes. Ouch. The strange thing is that the whole server was affected, even when running this against a single site. This met the first 3 objectives. Unfortunately all sites on that server would be affected, blowing the 4th objective out of the water. </span></p>
<p><span style="font-size: 10pt;">The other option I considered is manually changing all             the script mappings in the IIS snap-in. To change this manually, select the &#8220;Home             Directory&#8221; tab in IIS and click on the &#8220;Configuration&#8221; button. The &#8220;Mappings&#8221; tab             has all the mappings. The path to the alternate aspnet_isapi.dll can be changed             here. The problem is that this didn&#8217;t meet the 3rd objective because of the large             number of script mappings that had to be manually changed. </span></p>
<p><span style="font-size: 10pt;"><strong>Is a better solution possible?</strong> </span></p>
<p><span style="font-size: 10pt;">Needless to say, I had to go back to the drawing board             to find something that would work better. My initial guess was that doing this from             script would be difficult and would probably cause a similar interruption of service             to IIS. Fortunately I was wrong on both points. Not only did it turn out to be a             simple undertaking but there was zero, yes zero, impact on other sites. Even the             site being changed was not affected, other than Session State being reset. That             not only met all four of my objectives, it exceeded my expectations. </span></p>
<p><span style="font-size: 10pt;"><strong>The Solution</strong> </span></p>
<p><span style="font-size: 10pt;">Using </span><a href="http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/scrguide/sas_wsh_qlcc.asp"> <span style="font-size: 10pt; color: #0000ff;">WSH</span></a><span style="font-size: 10pt;"> I use an Input box and ask for the server, Site ID (more on the later) and the version                 to change to. Then </span><a href="http://www.microsoft.com/windows2000/techinfo/howitworks/activedirectory/adsilinks.asp"> <span style="font-size: 10pt; color: #0000ff;">ADSI</span></a><span style="font-size: 10pt;"> is used to retrieve the current script mappings and do a search-and-replace from                         the previous version to the new version. </span></p>
<p><span style="font-size: 10pt;">There are a number of ways to obtain the siteID in IIS.             My favorite is to go into the properties of the site from the IIS snap-in and click             on the &#8220;Properties&#8221; button in the Logging section. At the bottom, you&#8217;ll notice             a &#8220;Log file name&#8221;. It will start with W3SVC??. For example, it might be W3SVC1 or             W3SVC99. It&#8217;s the number after the W3SVC that counts. (i.e. W3SVC1 is SiteID 1,             W3SVC99 is SiteID 99). </span></p>
<p><span style="font-size: 10pt;">At the risk of boring the casual reader I feel I must mention one more thing that was tested. The script mappings are usually inherited from the default mappings for the server. IIS uses its own storage system called the Metabase which is similar in concept to Windows Registry. The first time a site or sub-folder within a site is assigned specific script mappings, it will write its own copy of the script mappings to its area of the metabase. Any new changes to the script mappings will be written against the new copy. ChangeFramework.vbs will work correctly whether or not the custom script mappings are in place. </span></p>
<p><span style="font-size: 10pt;">To use this script, simply save to your computer and double-click.             This is freely available to use by all, but I request that you keep the header in             place to give credit to both myself and ORCS Web, Inc. There is no warranty whatsoever             so if your computer blows up or falls over dead, don&#8217;t come looking to me for help.             But, the disclaimer aside, we&#8217;ve been running this for over 1/2 year on live production             servers and it was worked 100% of the time without incident and I personally attest             to its stability and trustworthiness. </span></p>
<p><span style="font-size: 10pt;"><strong>Download</strong> </span></p>
<p><span style="font-size: 10pt;">The script itself can be found at </span><a href="http://www.orcsweb.com/articles/ChangeFramework.zip"> <span style="font-size: 10pt; color: #0000ff;">http://www.orcsweb.com/articles/ChangeFramework.zip</span></a><span style="font-size: 10pt;"> </span></p>
<p><span style="font-size: 10pt;">It should be pretty obvious by this doesn&#8217;t install the             framework. It simply switches between versions that are already installed on your             computer. </span></p>
<blockquote><p><em><span style="font-size: 10pt;">Scott Forsyth is Director of IT at </span><a href="http://www.orcsweb.com/"> <span style="font-size: 10pt; color: #0000ff;">ORCS Web, Inc.</span></a><span style="font-size: 10pt;"> &#8211; a company that provides managed hosting solutions for clients who develop and deploy their applications on Microsoft Windows platforms. Services include shared hosting, dedicated hosting, and webfarm hosting, with specialty in .Net, SQL Server, and architecting highly scalable solutions. </span></em></p></blockquote>
<p>Quote: http://www.orcsweb.com/articles/change_framework.aspx</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]IIS ASP.NET 1.1与2.0共存</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">ASPNET_regiis.exe Tool, Setting the Default Version Without Forcing an Upgrade on All Sites</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/04/15/switching-versions-of-the-aspnet-framework-the-fast-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASPNET_regiis.exe Tool, Setting the Default Version Without Forcing an Upgrade on All Sites</title>
		<link>http://jennal.cn/2009/04/15/aspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites/</link>
		<comments>http://jennal.cn/2009/04/15/aspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 03:17:48 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[aspnet_regiis]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=152</guid>
		<description><![CDATA[Starting in the first version of ASP.NET, Microsoft has provided a tool to control which version of the framework is registered in IIS. This tool, aspnet_regiis.exe, is quite flexible and with the right understanding of how IIS and ASP.NET work, can be used for most any situation.
The most common parameter is -i. This is the [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]IIS ASP.NET 1.1与2.0共存</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Switching Versions of the ASP.Net Framework – The Fast Way</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">深入sql server中的事务</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>Starting in the first version of ASP.NET, Microsoft has provided a tool to control which version of the framework is registered in IIS. This tool, aspnet_regiis.exe, is quite flexible and with the right understanding of how IIS and ASP.NET work, can be used for most any situation.</p>
<p>The most common parameter is <strong><em>-i</em></strong>. This is the full blown registration of the framework in IIS, including all sites and all vdirs. For example, let&#8217;s say you wanted your entire server to be registered using ASP.NET v2.0, then you would navigate to the v2.0 framework folder (%windir%\Microsoft.NET\Framework\v2.0.50727) and type <strong><em>aspnet_regiis -i</em></strong>. Likewise, you can navigate to (%windir%\Microsoft.NET\Framework\v1.1.4322) and run the same command to set v1.1 on all sites. This is a great way to repair a broken installation or force a particular framework version to apply to your whole server.</p>
<p>But this catch-all registration is too aggressive for many production servers. That&#8217;s where the other parameters come in.</p>
<p>To see a detailed list of commands, type <strong><em>aspnet_regiis /?</em></strong> from the command prompt. I&#8217;m going to explain two of them: <strong><em>-lk</em></strong> and <strong><em>-sn</em></strong>. With these commands, we can apply the script mappings on just some of the sites on the server and update the default.</p>
<p><strong>Careful on Production Servers</strong></p>
<p><em>Note: First a disclaimer. Running any aspnet_regiis commands that make a change to IIS will cause <strong>all </strong>sites on the server to have a short interruption of service. Even if you run the path specific commands which I’ll explain below, all sites will have some downtime. To make changes on production servers without any downtime, you&#8217;ll need to write a solution to update the script mapping directly. Here&#8217;s an <strong>old</strong> article of mine that explains this in more depth:<br />
</em><em><a href="http://www.orcsweb.com/articles/change_framework.aspx">http://www.orcsweb.com/articles/change_framework.aspx</a> (Someday I&#8217;ll rewrite that article with an updated script to handle more than 2 versions of the framework, and IIS6 application pool support.)</em></p>
<p><em>While I&#8217;m offering disclaimers, make sure not to run multiple versions of the framework in the same Application Pool in IIS6.0: <a href="http://weblogs.asp.net/owscott/archive/2006/01/26/436607.aspx"></p>
<p>http://weblogs.asp.net/owscott/archive/2006/01/26/436607.aspx</a></em></p>
<p><strong>IIS Inheritance</strong></p>
<p>Let me digress again and explain how IIS inheritance works for the script mappings. IIS has a path structure similar to the file system on your computer. For example, the web part of the structure starts with /W3SVC/. Site #1 stores the script mappings in /W3SVC/1/ROOT/. Site #51 stores them in /W3SVC/51/ROOT/, and so on. If the script mappings are specifically set on a particular path then IIS will use those settings. But if they aren&#8217;t set then it will use the settings from the site or server root.</p>
<p><strong>ASP.NET Version Defaults</strong></p>
<p>When ASP.NET v1.1 was released, if you ran the install, it would apply your settings to all sites on the server, thus changing your framework version from v1.0 to v1.1. This meant that you had to be careful if you wanted to keep version 1.0 as the default. The install had some command line options to give more flexibility.</p>
<p>Version 2.0 of the framework is different and not as aggressive during the installation. Now it doesn&#8217;t make itself the default and you are required to specifically set it as the default if that is what you want. This is a good thing and is a better behavior than the v1.1 installation.</p>
<p><strong>Don&#8217;t forget to take a backup</strong></p>
<p><em>Warning: At this point, make sure to get a backup of IIS before continuing. If you do something wrong, you can restore it and everything will be brought back to its original state.</p>
<p><strong>Displaying The Current Settings</strong></p>
<p></em><strong>Displaying The Current Settings</strong></p>
<p>The aspnet_regiis tool has a neat way to see what is currently applied in IIS right now. You can do this by typing <strong><em>aspnet_regiis -lk</em></strong> from any framework folder. This will give something like this: (you can do this read-only command without any downtime on your server)</p>
<p>W3SVC/ 1.1.4322.2300<br />
W3SVC/1/ROOT/ 2.0.50727.0<br />
W3SVC/3/root/ 1.1.4322.2300<br />
W3SVC/6/root/ 1.1.4322.2300<br />
W3SVC/7/root/ 2.0.50727.0</p>
<p>Notice on this test server that the root, site #3 and site #6 are using v1.1 of the framework and site #1 and #7 are using v2.0. (Here is an article to find out which site is using which SiteID: <a href="http://weblogs.asp.net/owscott/archive/2005/07/29/421058.aspx">http://weblogs.asp.net/owscott/archive/2005/07/29/421058.aspx</a>)</p>
<p>Notice the gaps in numbers as #2, #4 and #5 aren&#8217;t set. This means that they will inherit their settings from /W3SVC/ which is currently using v1.1.</p>
<p>Now, the issue we have is that when setting up new sites, they will always use version 1.1 of the framework. Since v2.0 has all of the latest and greatest features, we want new sites to use v2.0 but make sure that existing sites aren&#8217;t changed. In our example here, let&#8217;s say that we want to upgrade the server to use v2.0 of the framework as the default version, but we don&#8217;t want sites #2, #3 or #6 to be upgraded.</p>
<p>If we run <strong><em>aspnet_regiis -i</em></strong> then we&#8217;ll force everything to version 2.0 which we don&#8217;t want. And if we upgrade just the root, then too many of the sites will be upgraded, which is also what we don&#8217;t want.</p>
<p><strong>The Magic</strong></p>
<p>The trick is to force all sites that you don&#8217;t want to upgrade to use v1.1, and then we can upgrade the root to v2.0. Then all new sites created after this will use v2.0.</p>
<p>Sites #3 and #6 are easy, they are already done for us. But site #2 needs to be set to specifically use v1.1 of the framework. This can be done by running aspnet_regiis from the v2.0 framework folder using this command: <strong><em>aspnet_regiis -sn W3SVC/2/ROOT/</em></strong>. Now running <strong><em>aspnet_regiis -lk</em></strong> will return this:</p>
<p>W3SVC/ 1.1.4322.2300<br />
W3SVC/1/ROOT/ 2.0.50727.0<br />
W3SVC/2/Root/ 1.1.4322.2300<br />
W3SVC/3/root/ 1.1.4322.2300<br />
W3SVC/6/root/ 1.1.4322.2300<br />
W3SVC/7/root/ 2.0.50727.0</p>
<p>For the purpose of this example, we&#8217;re going to let site #4 and #5 continue to inherit from the root, so after the next step they will be upgraded (using inheritance) to use version 2.0 of the framework.</p>
<p>The final step is to update the W3SVC/ node without touching anything else. As I&#8217;m sure you&#8217;ve guessed by now, this is done using: <strong><em>aspnet_regiis -sn W3SVC/</em></strong>.  Now we&#8217;re done, let&#8217;s look at the final result:</p>
<p>W3SVC/ 2.0.50727.0<br />
W3SVC/1/ROOT/ 2.0.50727.0<br />
W3SVC/2/Root/ 1.1.4322.2300<br />
W3SVC/3/root/ 1.1.4322.2300<br />
W3SVC/6/root/ 1.1.4322.2300<br />
W3SVC/7/root/ 2.0.50727.0</p>
<p>Success! Now sites #4 and #5 and all new sites will use the W3SVC/ setting, which is v2.0. Sites #1 and #7 will also use v2.0 because they were specifically set. Sites #2, #3 and #6 will continue running version 1.1 of the framework.</p>
<p><strong>Summary</strong></p>
<p>We&#8217;ve applied version 2.0 of the framework as the system default while allowing some sites to continue to run version 1.1 of the framework.</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]IIS ASP.NET 1.1与2.0共存</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Switching Versions of the ASP.Net Framework – The Fast Way</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">深入sql server中的事务</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/04/15/aspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[转]IIS ASP.NET 1.1与2.0共存</title>
		<link>http://jennal.cn/2009/04/15/%e8%bd%aciis-aspnet-11%e4%b8%8e20%e5%85%b1%e5%ad%98/</link>
		<comments>http://jennal.cn/2009/04/15/%e8%bd%aciis-aspnet-11%e4%b8%8e20%e5%85%b1%e5%ad%98/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 02:45:46 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=149</guid>
		<description><![CDATA[各位在同一电脑上同时安装并运行.net 1.1 和 .net 2.0 两个版本的朋友要小心啊！
您的项目是不是时不时会出现 Server Application Unavailable 错误呢？或者一直连续都出这个错误!
今天帮一个老师升级一个web的心理测评系统.那个系统原来是ASP.NET 1.1的,新版本是ASP.NET 2.0的..(PS:那台服务器上面还装其他的ASP.NET程序,用的是ASP.NET1.1的.)
1、在服务器上创建一个目录，然后将发布后的所有Web程序的文件复制到这个新建的目录。
2、在服务器的IIS上新建一个虚拟目录，然后 将其配置成可以执行脚本的应用程序，（过程与创建.net Framework 1.1版本的程序相同。） 然后，将此虚拟目录的.net Framework 配置成2.0。
大功告成后，开始访问刚配置的程序，却得到如下错误：
Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable. Please hit the &#8220;Refresh&#8221; button in your web browser to retry your request.
Administrator Note: An error message detailing the cause of [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Switching Versions of the ASP.Net Framework – The Fast Way</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">ASPNET_regiis.exe Tool, Setting the Default Version Without Forcing an Upgrade on All Sites</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>各位在同一电脑上同时安装并运行.net 1.1 和 .net 2.0 两个版本的朋友要小心啊！</p>
<p>您的项目是不是时不时会出现 Server Application Unavailable 错误呢？或者一直连续都出这个错误!</p>
<p>今天帮一个老师升级一个web的心理测评系统.那个系统原来是ASP.NET 1.1的,新版本是ASP.NET 2.0的..(PS:那台服务器上面还装其他的ASP.NET程序,用的是ASP.NET1.1的.)</p>
<p>1、在服务器上创建一个目录，然后将发布后的所有Web程序的文件复制到这个新建的目录。<br />
2、在服务器的IIS上新建一个虚拟目录，然后 将其配置成可以执行脚本的应用程序，（过程与创建.net Framework 1.1版本的程序相同。） 然后，将此虚拟目录的.net Framework 配置成2.0。<br />
大功告成后，开始访问刚配置的程序，却得到如下错误：<br />
Server Application Unavailable<br />
The web application you are attempting to access on this web server is currently unavailable. Please hit the &#8220;Refresh&#8221; button in your web browser to retry your request.</p>
<p>Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.</p>
<p>经过仔细阅读了IIS帮助文档，才发现，原来这个错误是由 IIS6 应用程序隔离机制造成的。IIS默认的应用程序隔离机制被称为：“工作进程隔离模式”，在此模式中，应用程序被分为多个组，每个组就是一个“应用程序池” ，每个应用程序池之间是相互隔离的。 隔离的好处当然就是安全啦，稳定啦，等等。IIS中的每个应用程序池由一个“工作进程”分别进行管理，也就是&#8221;W3wp.exe&#8221; 。如果有多个应用程序池中的程序运行，我们就能看到多个w3wp.exe。 我们平时新建的虚拟目录都默认被指向IIS6的“DefaultAppPool&#8221; 中， 所以在默认情况下，不管你有多少个asp.net程序在运行，在“Windows任务管理器”中你只能看到一个w3wp.exe进程。</p>
<p>出现上述错误的原因是： .net Framework 2.0的程序与.net Framework1.1(或1.0)的程序被放入同一个应用程序池（默认情况下放入DefaultAppPool池），也就是由同一个工作进程: w3wp.exe 进行管理，而单个工作进程是无法同时管理不同的程序（或者不同版本的程序）的。如果先访问.net framework 1.1的页面，则工作进程先加载并管理了 1.1版本的程序集，此时访问.net framework 2.0的web程序页面，Server Application Unavailable 错误就出来了。 反之，如果在默认应用程序池的w3wp.exe尚未启动前先访问了 2.0的web程序（此时应用程序集已经加载了.net framework2.0的Web程序集），再访问1.1或1.0的Web程序页面时，同样会出现“服务器应用程序不可用” 这样的中文提示。（您可以结束掉以前的w3wp.exe进行测试。）</p>
<p>解决办法： 在IIS中新建一个应用程序池,叫&#8221;ASP.NET2.0&#8243;吧，然后选中那个系统的虚拟目录，点“属性”－》在“应用程序池” 中选择刚才新建的的应用程序池，点击“确定”。</p>
<p>转自：</p>
<p>http://hi.baidu.com/wuwenlin/blog/item/fd6fdff245083615b07ec529.html</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Switching Versions of the ASP.Net Framework – The Fast Way</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Faspnet_regiisexe-tool-setting-the-default-version-without-forcing-an-upgrade-on-all-sites%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">ASPNET_regiis.exe Tool, Setting the Default Version Without Forcing an Upgrade on All Sites</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/04/15/%e8%bd%aciis-aspnet-11%e4%b8%8e20%e5%85%b1%e5%ad%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sql server 2005 分页</title>
		<link>http://jennal.cn/2009/04/14/sql-server-2005-%e5%88%86%e9%a1%b5/</link>
		<comments>http://jennal.cn/2009/04/14/sql-server-2005-%e5%88%86%e9%a1%b5/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 11:55:40 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[MS SQL Server 2005]]></category>
		<category><![CDATA[分页]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=143</guid>
		<description><![CDATA[今天上csdn，看到有人在炫耀自己所谓的分页算法，呃。。。我觉得算不上是什么算法，就是一种解决方案吧。不过回帖的人好多，在回帖里淘到了不错的东西，发上来记录一下。

1
2
3
4
5
6
7
WITH OrderedOrders AS
&#40;SELECT *,
ROW_NUMBER&#40;&#41; OVER &#40;ORDER BY &#91;id&#93;&#41;AS RowNumber　　--id是用来排序的列
FROM table_info &#41; --table_info是表名
SELECT *
FROM OrderedOrders
WHERE RowNumber BETWEEN 50 AND 60;

在windows server 2003, sql server 2005 CTP,P4 2.66GHZ,1GB 内存下测试，执行时间0秒  ，表中数据量230万
接下来大批量的数据查询性能瓶颈就在count了，不知道sql server 2005在这方面有没有什么改进.
附另一种方法:

1
2
3
4
SELECT *
FROM &#40;SELECT *,ROW_NUMBER&#40;&#41; Over&#40;ORDER BY id&#41; AS rowNum 
FROM table_info &#41; AS myTable
WHERE rowNum BETWEEN 50 AND 60;

<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="深入sql server中的事务" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://jennal.cn/wp-content/themes/compositio/images/avatar-replace.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">深入sql server中的事务</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Wordpress在首页文章显示评论的方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2010%2F01%2F31%2Fwordpress%25E5%259C%25A8%25E9%25A6%2596%25E9%25A1%25B5%25E6%2596%2587%25E7%25AB%25A0%25E6%2598%25BE%25E7%25A4%25BA%25E8%25AF%2584%25E8%25AE%25BA%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://jennal.cn/wp-content/themes/compositio/images/avatar-replace.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Wordpress在首页文章显示评论的方法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="漫画下载器GUI版问世" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F12%2F23%2F%25E6%25BC%25AB%25E7%2594%25BB%25E4%25B8%258B%25E8%25BD%25BD%25E5%2599%25A8gui%25E7%2589%2588%25E9%2597%25AE%25E4%25B8%2596%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/02/24/2911544.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">漫画下载器GUI版问世</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="漫画下载器 v1.6.8" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2011%2F11%2F21%2F%25E6%25BC%25AB%25E7%2594%25BB%25E4%25B8%258B%25E8%25BD%25BD%25E5%2599%25A8-v1-6-8%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/21/11189295.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">漫画下载器 v1.6.8</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>今天上csdn，看到有人在炫耀自己所谓的分页算法，呃。。。我觉得算不上是什么算法，就是一种解决方案吧。不过回帖的人好多，在回帖里淘到了不错的东西，发上来记录一下。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">WITH</span> OrderedOrders <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*,</span>
ROW_NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> OVER <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #993333; font-weight: bold;">AS</span> RowNumber　　<span style="color: #808080; font-style: italic;">--id是用来排序的列</span>
<span style="color: #993333; font-weight: bold;">FROM</span> table_info <span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">--table_info是表名</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span>
<span style="color: #993333; font-weight: bold;">FROM</span> OrderedOrders
<span style="color: #993333; font-weight: bold;">WHERE</span> RowNumber <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">50</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">60</span>;</pre></td></tr></table></div>

<p>在windows server 2003, sql server 2005 CTP,P4 2.66GHZ,1GB 内存下测试，执行时间0秒  ，表中数据量230万</p>
<p>接下来大批量的数据查询性能瓶颈就在count了，不知道sql server 2005在这方面有没有什么改进.</p>
<p>附另一种方法:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span>
<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*,</span>ROW_NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> Over<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> rowNum 
<span style="color: #993333; font-weight: bold;">FROM</span> table_info <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> myTable
<span style="color: #993333; font-weight: bold;">WHERE</span> rowNum <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">50</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">60</span>;</pre></td></tr></table></div>

<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="4"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="深入sql server中的事务" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://jennal.cn/wp-content/themes/compositio/images/avatar-replace.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">深入sql server中的事务</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Wordpress在首页文章显示评论的方法" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2010%2F01%2F31%2Fwordpress%25E5%259C%25A8%25E9%25A6%2596%25E9%25A1%25B5%25E6%2596%2587%25E7%25AB%25A0%25E6%2598%25BE%25E7%25A4%25BA%25E8%25AF%2584%25E8%25AE%25BA%25E7%259A%2584%25E6%2596%25B9%25E6%25B3%2595%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://jennal.cn/wp-content/themes/compositio/images/avatar-replace.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Wordpress在首页文章显示评论的方法</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="漫画下载器 v1.6.1" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2010%2F08%2F22%2F%25E6%25BC%25AB%25E7%2594%25BB%25E4%25B8%258B%25E8%25BD%25BD%25E5%2599%25A8-v1-6-1%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/02/24/2910925.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">漫画下载器 v1.6.1</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="漫画下载器 v1.6" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2010%2F08%2F03%2F%25E6%25BC%25AB%25E7%2594%25BB%25E4%25B8%258B%25E8%25BD%25BD%25E5%2599%25A8-v1-6%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/02/24/2910930.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 15px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">漫画下载器 v1.6</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="4" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/04/14/sql-server-2005-%e5%88%86%e9%a1%b5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#的疑问</title>
		<link>http://jennal.cn/2009/04/02/c%e7%9a%84%e7%96%91%e9%97%ae/</link>
		<comments>http://jennal.cn/2009/04/02/c%e7%9a%84%e7%96%91%e9%97%ae/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 01:36:05 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#的疑问]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=136</guid>
		<description><![CDATA[
1
2
3
4
5
6
class User&#123;
    public IPAddress IP;
&#125;
User user = null;
if&#40; user == null &#124;&#124; user.IP == null &#41; //这句会发生莫名的错误，程序直接退出，是C#的问题吗？
&#123;&#125;

<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于C#反射很棒的文章</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> User<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">public</span> IPAddress IP<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
User user <span style="color: #000080;">=</span> null<span style="color: #008080;">;</span>
<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> user <span style="color: #000080;">==</span> null <span style="color: #000040;">||</span> user.<span style="color: #007788;">IP</span> <span style="color: #000080;">==</span> null <span style="color: #008000;">&#41;</span> <span style="color: #666666;">//这句会发生莫名的错误，程序直接退出，是C#的问题吗？</span>
<span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F28%2F%25E5%2585%25B3%25E4%25BA%258Ec%25E5%258F%258D%25E5%25B0%2584%25E5%25BE%2588%25E6%25A3%2592%25E7%259A%2584%25E6%2596%2587%25E7%25AB%25A0%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于C#反射很棒的文章</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">一个C#睡前故事</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/04/02/c%e7%9a%84%e7%96%91%e9%97%ae/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>一个C#睡前故事</title>
		<link>http://jennal.cn/2009/03/23/%e4%b8%80%e4%b8%aac%e7%9d%a1%e5%89%8d%e6%95%85%e4%ba%8b/</link>
		<comments>http://jennal.cn/2009/03/23/%e4%b8%80%e4%b8%aac%e7%9d%a1%e5%89%8d%e6%95%85%e4%ba%8b/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 12:01:31 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[回调]]></category>
		<category><![CDATA[异步]]></category>
		<category><![CDATA[线程]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=129</guid>
		<description><![CDATA[从 前，在南方一块奇异的土地上，有个工人名叫彼得，他非常勤奋，对他的老板总是百依百顺。但是他的老板是个吝啬的人，从不信任别人，坚决要求随时知道彼得的 工作进度，以防止他偷懒。但是彼得又不想让老板呆在他的办公室里站在背后盯着他，于是就对老板做出承诺：无论何时，只要我的工作取得了一点进展我都会及时 让你知道。彼得通过周期性地使用“带类型的引用”(原文为：“typed reference” 也就是delegate？？)“回调”他的老板来实现他的承诺，如下： 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Worker &#123;
	public void Advise&#40;Boss boss&#41; &#123; _boss = boss; &#125;
	public void DoWork&#40;&#41; &#123;
		Console.WriteLine&#40;“工作: 工作开始”&#41;;
		if&#40; _boss != null &#41; _boss.WorkStarted&#40;&#41;;
&#160;
		Console.WriteLine&#40;“工作: 工作进行中”&#41;;
		if&#40; _boss != null &#41; _boss.WorkProgressing&#40;&#41;;
&#160;
		Console.WriteLine&#40;&#34;工作: 工作完成&#34;&#41;;
		if&#40; _boss != null &#41; &#123;
			int grade = _boss.WorkCompleted&#40;&#41;;
			Console.WriteLine&#40;“工人的工作得分＝” + grade&#41;;
		&#125;
	&#125;
	private Boss _boss;
&#125;
&#160;
class Boss &#123;
	public void WorkStarted&#40;&#41; &#123; /* 老板不关心。 */ &#125;
	public void [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#的疑问</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">从 前，在南方一块奇异的土地上，有个工人名叫彼得，他非常勤奋，对他的老板总是百依百顺。但是他的老板是个吝啬的人，从不信任别人，坚决要求随时知道彼得的 工作进度，以防止他偷懒。但是彼得又不想让老板呆在他的办公室里站在背后盯着他，于是就对老板做出承诺：无论何时，只要我的工作取得了一点进展我都会及时 让你知道。彼得通过周期性地使用“带类型的引用”(原文为：“typed reference” 也就是delegate？？)“回调”他的老板来实现他的承诺，如下： </p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Worker <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Advise<span style="color: #008000;">&#40;</span>Boss boss<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> _boss <span style="color: #000080;">=</span> boss<span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> DoWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工作<span style="color: #008080;">:</span> 工作开始”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> _boss <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> _boss.<span style="color: #007788;">WorkStarted</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工作<span style="color: #008080;">:</span> 工作进行中”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> _boss <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> _boss.<span style="color: #007788;">WorkProgressing</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;工作: 工作完成&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> _boss <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">int</span> grade <span style="color: #000080;">=</span> _boss.<span style="color: #007788;">WorkCompleted</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工人的工作得分＝” <span style="color: #000040;">+</span> grade<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">private</span> Boss _boss<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Boss <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> WorkStarted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #ff0000; font-style: italic;">/* 老板不关心。 */</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> WorkProgressing<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #ff0000; font-style: italic;">/*老板不关心。 */</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> WorkCompleted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“时间差不多！”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* 总分为10 */</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Universe <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Worker  peter <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Worker<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Boss        boss <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Boss<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">Advise</span><span style="color: #008000;">&#40;</span>boss<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">DoWork</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“Main<span style="color: #008080;">:</span> 工人工作完成”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Console.<span style="color: #007788;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>接口</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 现在，彼得成了一个特殊的人，他不但能容忍吝啬的老板，而且和他周围的宇宙也有了密切的联系，以至于他认为宇宙对他的工作进度也感兴趣。不幸的是，他必须也给宇宙添加一个特殊的回调函数Advise来实现同时向他老板和宇宙报告工作进度。彼得想要把潜在的通知的列表和这些通知的实现方法分离开来，于是他决定把方法分离为一个接口：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">interface IWorkerEvents <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">void</span> WorkStarted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">void</span> WorkProgressing<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> WorkCompleted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Worker <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Advise<span style="color: #008000;">&#40;</span>IWorkerEvents events<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> _events <span style="color: #000080;">=</span> events<span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> DoWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;工作工作开始&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> _events <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> _events.<span style="color: #007788;">WorkStarted</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;工作: 工作进行中&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_events <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> _events.<span style="color: #007788;">WorkProgressing</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;工作: 工作完成&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>_events <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">int</span> grade <span style="color: #000080;">=</span> _events.<span style="color: #007788;">WorkCompleted</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
			Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;工人的工作得分＝&quot;</span> <span style="color: #000040;">+</span> grade<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">private</span> IWorkerEvents _events<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Boss <span style="color: #008080;">:</span> IWorkerEvents <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> WorkStarted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #ff0000; font-style: italic;">/* 老板不关心。 */</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> WorkProgressing<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #ff0000; font-style: italic;">/* 老板不关心。 */</span> <span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> WorkCompleted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“时间差不多！”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">3</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* 总分为10 */</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>委托</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 不幸的是，每当彼得忙于通过接口的实现和老板交流时，就没有机会及时通知宇宙了。至少他应该忽略身在远方的老板的引用，好让其他实现了IWorkerEvents的对象得到他的工作报告。（”At least he&#8217;d abstracted the reference of his boss far away from him so that others who implemented the IWorkerEvents interface could be notified of his work progress” 原话如此，不理解到底是什么意思:)）</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 他的老板还是抱怨得很厉害。“彼得！”他老板吼道，“你为什么在工作一开始和工作进行中都来烦我？！我不关心这些事件。你不但强迫我实现了这些方法，而且还在浪费我宝贵的工作时间来处理你的事件，特别是当我外出的时候更是如此！你能不能不再来烦我？”</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 于是，彼得意识到接口虽然在很多情况都很有用，但是当用作事件时，“粒度”不够好。他希望能够仅在别人想要时才通知他们，于是他决定把接口的方法分离为单独的委托，每个委托都像一个小的接口方法：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">delegate <span style="color: #0000ff;">void</span> WorkStarted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
delegate <span style="color: #0000ff;">void</span> WorkProgressing<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
delegate <span style="color: #0000ff;">int</span> WorkCompleted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Worker <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> DoWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工作<span style="color: #008080;">:</span> 工作开始”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> started <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> started<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工作<span style="color: #008080;">:</span> 工作进行中”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> progressing <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> progressing<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;“工作: 工作完成”&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> completed <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">int</span> grade <span style="color: #000080;">=</span> completed<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工人的工作得分＝” <span style="color: #000040;">+</span> grade<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">public</span> WorkStarted started<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">public</span> WorkProgressing progressing<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">public</span> WorkCompleted completed<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Boss <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> WorkCompleted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Better...&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* 总分为10 */</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Universe <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Worker  peter <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Worker<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Boss        boss <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Boss<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">completed</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> WorkCompleted<span style="color: #008000;">&#40;</span>boss.<span style="color: #007788;">WorkCompleted</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">DoWork</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“Main<span style="color: #008080;">:</span> 工人工作完成”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Console.<span style="color: #007788;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>静态监听者</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 这样，彼得不会再拿他老板不想要的事件来烦他老板了，但是他还没有把宇宙放到他的监听者列表中。因为宇宙是个包涵一切的实体，看来不适合使用实例方法的委托（想像一下，实例化一个“宇宙”要花费多少资源…..），于是彼得就需要能够对静态委托进行挂钩，委托对这一点支持得很好：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Universe <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> WorkerStartedWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Universe notices worker starting work&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> WorkerCompletedWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Universe pleased with worker's work&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">7</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		Worker  peter <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Worker<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Boss        boss <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Boss<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">completed</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> WorkCompleted<span style="color: #008000;">&#40;</span>boss.<span style="color: #007788;">WorkCompleted</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">started</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> WorkStarted<span style="color: #008000;">&#40;</span>Universe.<span style="color: #007788;">WorkerStartedWork</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">completed</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> WorkCompleted<span style="color: #008000;">&#40;</span>Universe.<span style="color: #007788;">WorkerCompletedWork</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		peter.<span style="color: #007788;">DoWork</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“Main<span style="color: #008080;">:</span> 工人工作完成”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Console.<span style="color: #007788;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>事件</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 不幸的是，宇宙太忙了，也不习惯时刻关注它里面的个体，它可以用自己的委托替换了彼得老板的委托。这是把彼得的Worker类的的委托字段做成public的一个无意识的副作用。同样，如果彼得的老板不耐烦了，也可以决定自己来激发彼得的委托（真是一个粗鲁的老板）：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Peter's boss taking matters into his own hands</span>
<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> peter.<span style="color: #007788;">completed</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> peter.<span style="color: #007788;">completed</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p> 彼得不想让这些事发生，他意识到需要给每个委托提供“注册”和“反注册”功能，这样监听者就可以自己添加和移除委托，但同时又不能清空整个列表也不能随意激发彼得的事件了。彼得并没有来自己实现这些功能，相反，他使用了event关键字让C#编译器为他构建这些方法：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Worker <span style="color: #008000;">&#123;</span>
	...
	<span style="color: #0000ff;">public</span> event WorkStarted started<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">public</span> event WorkProgressing progressing<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">public</span> event WorkCompleted completed<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 彼得知道event关键字在委托的外边包装了一个property，仅让C#客户通过+= 和 -=操作符来添加和移除，强迫他的老板和宇宙正确地使用事件。</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	Worker  peter <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Worker<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	Boss        boss <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Boss<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	peter.<span style="color: #007788;">completed</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> WorkCompleted<span style="color: #008000;">&#40;</span>boss.<span style="color: #007788;">WorkCompleted</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	peter.<span style="color: #007788;">started</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> WorkStarted<span style="color: #008000;">&#40;</span>Universe.<span style="color: #007788;">WorkerStartedWork</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	peter.<span style="color: #007788;">completed</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> WorkCompleted<span style="color: #008000;">&#40;</span>Universe.<span style="color: #007788;">WorkerCompletedWork</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	peter.<span style="color: #007788;">DoWork</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“Main<span style="color: #008080;">:</span> 工人工作完成”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	Console.<span style="color: #007788;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong><span style="background: white none repeat scroll 0% 50%; line-height: 185%; font-family: verdana; color: #444444;">“</strong><strong>收获</strong><strong><span style="background: white none repeat scroll 0% 50%; line-height: 185%; font-family: verdana; color: #444444;">”</strong><strong>所有结果</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 到这时，彼得终于可以送一口气了，他成功地满足了所有监听者的需求，同时避免了与特定实现的紧耦合。但是他注意到他的老板和宇宙都为它的工作打了分，但是他仅仅接收了一个分数。面对多个监听者，他想要“收获”所有的结果，于是他深入到代理里面，轮询监听者列表，手工一个个调用：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> DoWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	...
	<span style="color: #007788;">Console</span>.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;“工作: 工作完成”&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> completed <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		foreach<span style="color: #008000;">&#40;</span> WorkCompleted wc in completed.<span style="color: #007788;">GetInvocationList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">int</span> grade <span style="color: #000080;">=</span> wc<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工人的工作得分＝” <span style="color: #000040;">+</span> grade<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>异步通知：激发</strong><strong><span style="background: white none repeat scroll 0% 50%; line-height: 185%; font-family: verdana; color: #444444;"> &amp; </strong><strong>忘掉</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 同时，他的老板和宇宙还要忙于处理其他事情，也就是说他们给彼得打分所花费的事件变得非常长：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Boss <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> WorkCompleted<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">3000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Better...&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">6</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* 总分为10 */</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">class</span> Universe <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> WorkerCompletedWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">4000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Universe is pleased with worker's work&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">7</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	...
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p> 很不幸，彼得每次通知一个监听者后必须等待它给自己打分，现在这些通知花费了他太多的工作事件。于是他决定忘掉分数，仅仅异步激发事件：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> DoWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	...
	<span style="color: #007788;">Console</span>.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;“工作: 工作完成”&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> completed <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		foreach<span style="color: #008000;">&#40;</span> WorkCompleted wc in completed.<span style="color: #007788;">GetInvocationList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			wc.<span style="color: #007788;">BeginInvoke</span><span style="color: #008000;">&#40;</span>null, null<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>异步通知：轮询</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 这使得彼得可以通知他的监听者，然后立即返回工作，让进程的线程池来调用这些代理。随着时间的过去，彼得发现他丢失了他工作的反馈，他知道听取别人的赞扬和努力工作一样重要，于是他异步激发事件，但是周期性地轮询，取得可用的分数。</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> DoWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	...
	<span style="color: #007788;">Console</span>.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;“工作: 工作完成”&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> completed <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		foreach<span style="color: #008000;">&#40;</span> WorkCompleted wc in completed.<span style="color: #007788;">GetInvocationList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			IAsyncResult res <span style="color: #000080;">=</span> wc.<span style="color: #007788;">BeginInvoke</span><span style="color: #008000;">&#40;</span>null, null<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span>res.<span style="color: #007788;">IsCompleted</span> <span style="color: #008000;">&#41;</span> System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">int</span> grade <span style="color: #000080;">=</span> wc.<span style="color: #007788;">EndInvoke</span><span style="color: #008000;">&#40;</span>res<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工人的工作得分＝” <span style="color: #000040;">+</span> grade<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>异步通知：委托</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 不幸地，彼得有回到了一开始就想避免的情况中来，比如，老板站在背后盯着他工作。于是，他决定使用自己的委托作为他调用的异步委托完成的通知，让他自己立即回到工作，但是仍可以在别人给他的工作打分后得到通知：</p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> DoWork<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	...
	<span style="color: #007788;">Console</span>.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;“工作: 工作完成”&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> completed <span style="color: #000040;">!</span><span style="color: #000080;">=</span> null <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		foreach<span style="color: #008000;">&#40;</span> WorkCompleted wc in completed.<span style="color: #007788;">GetInvocationList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			wc.<span style="color: #007788;">BeginInvoke</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> AsyncCallback<span style="color: #008000;">&#40;</span>WorkGraded<span style="color: #008000;">&#41;</span>, wc<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> WorkGraded<span style="color: #008000;">&#40;</span>IAsyncResult res<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	WorkCompleted wc <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>WorkCompleted<span style="color: #008000;">&#41;</span>res.<span style="color: #007788;">AsyncState</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">int</span> grade <span style="color: #000080;">=</span> wc.<span style="color: #007788;">EndInvoke</span><span style="color: #008000;">&#40;</span>res<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	Console.<span style="color: #007788;">WriteLine</span><span style="color: #008000;">&#40;</span>“工人的工作得分＝” <span style="color: #000040;">+</span> grade<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; margin-bottom: 3pt; text-align: center; line-height: 185%;" align="center"><strong>宇宙中的幸福</strong><strong></strong></p>
<p class="MsoNormal" style="background: white none repeat scroll 0% 50%; text-align: left;" align="left"> 彼得、他的老板和宇宙最终都满足了。彼得的老板和宇宙可以收到他们感兴趣的事件通知，减少了实现的负担和非必需的往返“差旅费”。彼得可以通知他们，而不管他们要花多长时间来从目的方法中返回，同时又可以异步地得到他的结果。彼得知道，这并不*十分*简单，因为当他异步激发事件时，方法要在另外一个线程中执行，彼得的目的方法完成的通知也是一样的道理。但是，迈克和彼得是好朋友，他很熟悉线程的事情，可以在这个领域提供指导。</p>
<p> 他们永远幸福地生活下去……&lt;完&gt;</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F09%2F24%2Fc%25E5%258A%25A8%25E6%2580%2581%25E5%258A%25A0%25E8%25BD%25BDdll%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#动态加载DLL</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F08%2F26%2Fc%25E8%25AA%259E%25E8%25A8%2580%25E6%2595%2599%25E7%25A8%258B-%25EF%25BC%2588%25E4%25B8%2580%25EF%25BC%2589%25E7%2592%25B0%25E5%25A2%2583%25E9%2585%258D%25E7%25BD%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C語言教程 — （一）環境配置</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F02%2Fc%25E7%259A%2584%25E7%2596%2591%25E9%2597%25AE%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F23%2F%25E4%25B8%2580%25E4%25B8%25AAc%25E7%259D%25A1%25E5%2589%258D%25E6%2595%2585%25E4%25BA%258B%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">C#的疑问</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/03/23/%e4%b8%80%e4%b8%aac%e7%9d%a1%e5%89%8d%e6%95%85%e4%ba%8b/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>深入sql server中的事务</title>
		<link>http://jennal.cn/2009/03/20/%e6%b7%b1%e5%85%a5sql-server%e4%b8%ad%e7%9a%84%e4%ba%8b%e5%8a%a1/</link>
		<comments>http://jennal.cn/2009/03/20/%e6%b7%b1%e5%85%a5sql-server%e4%b8%ad%e7%9a%84%e4%ba%8b%e5%8a%a1/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 08:24:52 +0000</pubDate>
		<dc:creator>Jennal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[MS SQL Server 2005]]></category>
		<category><![CDATA[mssql2005]]></category>

		<guid isPermaLink="false">http://jennal.cn/?p=127</guid>
		<description><![CDATA[一. 概述&#8230; 1
二. 并发访问的不利影响&#8230; 1
1. 脏读（dirty read）&#8230; 1
2. 不可重复读（nonrepeatable read）&#8230; 1
3. 幻读（phantom read）&#8230; 1
三. 并发访问的控制机制&#8230; 2
1. 锁&#8230; 2
2. 行版本控制&#8230; 2
四. 隔离级别&#8230; 2
五. 事务&#8230; 3
1. 事务的模式&#8230; 3
1.1. 显式事务（Explicit Transactions）&#8230; 3
1.2. 自动提交事务（Autocommit Transactions）&#8230; 4
1.3. 隐式事务（Implicit Transactions）&#8230; 4
2. 事务的编程&#8230; 5
2.1. Transact-SQL脚本&#8230; 5
2.2. ADO.NET应用程序接口&#8230; 5
一. 概述
当多个用户同时访问数据库的同一资源时，叫做并发访问。如果并发的访问中有用户对数据进行修改，很可能就会对其他访问同一资源的用户产生不利的影响。可能产生的并发不利影响有以下几类：脏读、不可重复读和幻读。
为了避免并发访问产生的不利影响，sql server设计有两种并发访问的控制机制：锁、行版本控制。
二. 并发访问的不利影响
并发访问，如果没有并发访问控制机制，可能产生的不利影响有以下几种
1. 脏读（dirty read）
如果一个用户在更新一条记录，这时第二个用户来读取这条更新了的记录，但是第一个用户在更新了记录后又反悔了，不修改了，回滚了刚才的 更新。这样，导致了第二个用户实际上读取到了一条根本就没有存在过的修改后的记录。如果第一个用户在修改记录期间，把所修改的记录锁住，在修改完成前别的 用户读取不到记录，就能避免这种情况。
2. 不可重复读（nonrepeatable read）
第一个用户在一次事务中读取同一记录两次，第一次读取一条记录后，又有第二个用户来访问这条记录，并修改了这条记录，第一个用户第二次 读取这条记录时，得到的是跟第一次不同的数据了。如果第一个用户在两次读取之间锁住要读取的记录，别的用户不能去修改相应的记录就能避免这种情况。
3. 幻读（phantom read）
第一个用户在一次事务中两次读取同样满足条件的一批记录，第一次读取一批记录后，又有第二个用户来访问这个表，并在这个表中插入或者删 除了一些记录，第一个用户第二次以同样条件读取这批记录时，可能得到的结果有些记录是在第一次读取时有，第二次的结果中没有了，或者是第二次读取的结果中 有的记录在第一次读取的结果中没有的。如果第一个用户在两次读取之间锁住要读取的记录，别的用户不能去修改相应的记录，也不能增删记录，就能避免这种情 [...]<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">sql server 2005 分页</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Switching Versions of the ASP.Net Framework – The Fast Way</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]IIS ASP.NET 1.1与2.0共存</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p><span><span><a href="#_Toc167987824"><span><span>一</span></span><span>.</span><span><span> </span></span><span><span>概述</span></span><span><span>&#8230; </span></span><span>1</span></a></span></span></p>
<p><span><span><a href="#_Toc167987825"><span><span>二</span></span><span>.</span><span><span> </span></span><span><span>并发访问<span>的<span>不利影响</span></span></span></span><span><span>&#8230; </span></span><span>1</span></a></span></span></p>
<p><span><span><a href="#_Toc167987826"><span>1.</span><span><span> </span></span><span><span>脏读（</span></span><span>dirty read</span><span><span>）</span></span><span><span>&#8230; </span></span><span>1</span></a></span></span></p>
<p><span><span><a href="#_Toc167987827"><span>2.</span><span><span> </span></span><span><span>不可重复读（</span></span><span>nonrepeatable read</span><span><span>）</span></span><span><span>&#8230; </span></span><span>1</span></a></span></span></p>
<p><span><span><a href="#_Toc167987828"><span>3.</span><span><span> </span></span><span><span>幻读（</span></span><span>phantom read</span><span><span>）</span></span><span><span>&#8230; </span></span><span>1</span></a></span></span></p>
<p><span><span><a href="#_Toc167987829"><span><span>三</span></span><span>.</span><span><span> </span></span><span><span>并发访问<span>的<span>控制机制</span></span></span></span><span><span>&#8230; </span></span><span>2</span></a></span></span></p>
<p><span><span><a href="#_Toc167987830"><span>1.</span><span><span> </span></span><span><span>锁</span></span><span><span>&#8230; </span></span><span>2</span></a></span></span></p>
<p><span><span><a href="#_Toc167987831"><span>2.</span><span><span> </span></span><span><span>行版本控制</span></span><span><span>&#8230; </span></span><span>2</span></a></span></span></p>
<p><span><span><a href="#_Toc167987832"><span><span>四</span></span><span>.</span><span><span> </span></span><span><span>隔离级别</span></span><span><span>&#8230; </span></span><span>2</span></a></span></span></p>
<p><span><span><a href="#_Toc167987833"><span><span>五</span></span><span>.</span><span><span> </span></span><span><span>事务</span></span><span><span>&#8230; </span></span><span>3</span></a></span></span></p>
<p><span><span><a href="#_Toc167987834"><span>1.</span><span><span> </span></span><span><span>事务的模式</span></span><span><span>&#8230; </span></span><span>3</span></a></span></span></p>
<p><span><span><a href="#_Toc167987835"><span>1.1.</span><span><span> </span></span><span><span>显式事务<span>（</span></span></span><span>Explicit Transactions</span><span><span>）</span></span><span><span>&#8230; </span></span><span>3</span></a></span></span></p>
<p><span><span><a href="#_Toc167987836"><span>1.2.</span><span><span> </span></span><span><span>自动提交事务<span>（</span></span></span><span>Autocommit Transactions</span><span><span>）</span></span><span><span>&#8230; </span></span><span>4</span></a></span></span></p>
<p><span><span><a href="#_Toc167987837"><span>1.3.</span><span><span> </span></span><span><span>隐式事务<span>（</span></span></span><span>Implicit Transactions</span><span><span>）</span></span><span><span>&#8230; </span></span><span>4</span></a></span></span></p>
<p><span><span><a href="#_Toc167987838"><span>2.</span><span><span> </span></span><span><span>事务的编程</span></span><span><span>&#8230; </span></span><span>5</span></a></span></span></p>
<p><span><span><a href="#_Toc167987839"><span>2.1.</span><span><span> </span></span><span>Transact-SQL</span><span><span>脚本</span></span><span><span>&#8230; </span></span><span>5</span></a></span></span></p>
<p><span><span><a href="#_Toc167987840"><span>2.2.</span><span><span> </span></span><span>ADO.NET</span><span><span>应用程序接口</span></span><span><span>&#8230; </span></span><span>5</span></a></span></span></p>
<h1><a name="_Toc167987824"><span><span>一.<span> </span></span></span><span>概述</span></a></h1>
<p><span>当多个用户同时访问数据库的同一资源时，叫做并发访问。如果并发的访问中有用户对数据进行修改，很可能就会对其他访问同一资源的用户产生不利的影响。可能产生的并发不利影响有以下几类：脏读、不可重复读和幻读。</span></p>
<p><span>为了避免并发访问产生的不利影响，</span><span>sql server</span><span>设计有两种并发访问的控制机制：锁、行版本控制。</span></p>
<h1><a name="_Toc167987825"><span><span>二.<span> </span></span></span><span>并发访问的不利影响</span></a></h1>
<p><span>并发访问，如果没有并发访问控制机制，可能产生的不利影响有以下几种</span></p>
<h2><a name="_Toc167987826"><span><span>1.<span> </span></span></span><span>脏读（</span></a><span><span>dirty read</span></span><span><span>）</span></span></h2>
<p><span>如果一个用户在更新一条记录，这时第二个用户来读取这条更新了的记录，但是第一个用户在更新了记录后又反悔了，不修改了，回滚了刚才的 更新。这样，导致了第二个用户实际上读取到了一条根本就没有存在过的修改后的记录。如果第一个用户在修改记录期间，把所修改的记录锁住，在修改完成前别的 用户读取不到记录，就能避免这种情况。</span></p>
<h2><a name="_Toc167987827"><span><span>2.<span> </span></span></span><span>不可重复读（</span></a><span><span>nonrepeatable read</span></span><span><span>）</span></span></h2>
<p><span>第一个用户在一次事务中读取同一记录两次，第一次读取一条记录后，又有第二个用户来访问这条记录，并修改了这条记录，第一个用户第二次 读取这条记录时，得到的是跟第一次不同的数据了。如果第一个用户在两次读取之间锁住要读取的记录，别的用户不能去修改相应的记录就能避免这种情况。</span></p>
<h2><a name="_Toc167987828"><span><span>3.<span> </span></span></span><span>幻读（</span></a><span><span>phantom read</span></span><span><span>）</span></span></h2>
<p><span>第一个用户在一次事务中两次读取同样满足条件的一批记录，第一次读取一批记录后，又有第二个用户来访问这个表，并在这个表中插入或者删 除了一些记录，第一个用户第二次以同样条件读取这批记录时，可能得到的结果有些记录是在第一次读取时有，第二次的结果中没有了，或者是第二次读取的结果中 有的记录在第一次读取的结果中没有的。如果第一个用户在两次读取之间锁住要读取的记录，别的用户不能去修改相应的记录，也不能增删记录，就能避免这种情 况。</span></p>
<h1><a name="_Toc167987829"><span><span>三.<span> </span></span></span><span>并发访问的控制机制</span></a></h1>
<p><span>Sql server</span><span>中提供了两种并发控制的机制以避免在并发访问时可能产生的不利影响。这两种机制是：</span></p>
<h2><a name="_Toc167987830"><span><span>1.<span> </span></span></span><span>锁</span></a></h2>
<p><span>每个事务对所依赖的资源（如行、页或表）请求不同类型的锁。锁可以阻止其他事务以某种可能会导致事务请求锁出错的方式修改资源。当事务不再依赖锁定的资源时，它将释放锁。</span></p>
<p><span>根据需要锁定资源的粒度和层次，锁有许多类型，主要的有几种：</span></p>
<p><span>表类型：锁定整个表</span></p>
<p><span>行类型：锁定某个行</span></p>
<p><span>文件类型：锁定某个数据库文件</span></p>
<p><span>数据库类型：锁定整个数据库</span></p>
<p><span>页类型：锁定</span><span>8K</span><span>为单位的数据库页</span></p>
<p><span>锁的粒度越小，锁定的范围越小，对别的访问的阻塞就越小，但是所用的锁可能会比较多，锁的消耗就比较大。锁的粒度越大，对别的访问的阻塞可能性就越大，但是所用的锁就会比较少，锁的消耗就比较小。</span></p>
<p><span>对于编程人员来说，不用手工去设置控制锁，</span><span>sql server</span><span>通过设置事务的隔离级别自动管理锁的设置和控制。</span></p>
<p><span>Sql server</span><span>专门管理锁的是锁管理器，锁管理器通过查询分析器分析待执行的</span><span>sql</span><span>语句，来判断语句将会访问哪些资源，进行什么操作，然后结合设定的隔离级别自动分配管理需要用到的锁。</span></p>
<h2><a name="_Toc167987831"><span><span>2.<span> </span></span></span><span>行版本控制</span></a></h2>
<p><span>当启用了基于行版本控制的隔离级别时，数据库引擎</span><span> </span><span>将维护修改的每一行的版本。应用程序可以指定事务使用行版本查看事务或查询开始时存在的数据，而不是使用锁保护所有读取。通过使用行版本控制，读取操作阻止其他事务的可能性将大大降低。</span></p>
<h1><a name="_Toc167987832"><span><span>四.<span> </span></span></span><span>隔离级别</span></a></h1>
<p><span>上面提到了，</span><span>sql server</span><span>通过设置隔离级别来控制锁的使用，从而实现并发法访问控制。</span></p>
<p><span>Microsoft SQL Server </span><span>数据库引擎支持所有这些隔离级别：</span></p>
<p><span><span>l<span> </span></span></span><span>未提交读（隔离事务的最低级别，只能保证不读取物理上损坏的数据）</span></p>
<p><span><span>l<span> </span></span></span><span>已提交读（数据库引擎的默认级别）</span></p>
<p><span><span>l<span> </span></span></span><span>可重复读</span></p>
<p><span><span>l<span> </span></span></span><span>可序列化（隔离事务的最高级别，事务之间完全隔离）</span></p>
<p><span>这几种隔离级别，对应上面三种并发访问可能产生的不利影响，分别有不同的效果，见下表：</span></p>
<table style="width: 825px; height: 122px;" border="1" cellspacing="0" cellpadding="0" width="825">
<tbody>
<tr>
<td>
<p align="center"><strong><span>隔离级别</span></strong><strong><span> </span></strong></p>
</td>
<td>
<p align="center"><strong><span>脏读</span></strong><strong><span> </span></strong></p>
</td>
<td>
<p align="center"><strong><span>不可重复读</span></strong><strong><span> </span></strong></p>
</td>
<td>
<p align="center"><strong><span>幻读</span></strong><strong><span> </span></strong></p>
</td>
</tr>
<tr>
<td>
<p align="left"><strong><span>未提交读</span></strong><span> </span></p>
</td>
<td>
<p align="left"><span>是</span></p>
</td>
<td>
<p align="left"><span>是</span></p>
</td>
<td>
<p align="left"><span>是</span></p>
</td>
</tr>
<tr>
<td>
<p align="left"><strong><span>已提交读</span></strong><span> </span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
<td>
<p align="left"><span>是</span></p>
</td>
<td>
<p align="left"><span>是</span></p>
</td>
</tr>
<tr>
<td>
<p align="left"><strong><span>可重复读</span></strong><span> </span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
<td>
<p align="left"><span>是</span></p>
</td>
</tr>
<tr>
<td>
<p align="left"><strong><span>快照</span></strong><span> </span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
</tr>
<tr>
<td>
<p align="left"><strong><span>可序列化</span></strong><span> </span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
<td>
<p align="left"><span>否</span></p>
</td>
</tr>
</tbody>
</table>
<h1><a name="_Toc167987833"><span><span>五.<span> </span></span></span><span>事务</span></a></h1>
<p><span>事务是一个逻辑上的单个的工作单元，其中可以包括许多操作，但是它们在逻辑上是一个整体，要么全部完成，要么全部失败，就好像什么操作都没进行似的。</span></p>
<p><span>事务是十分可靠坚固的机制，它能保证事务要么全部完成，要么能全部回滚。</span></p>
<p><span><span>l<span> </span></span></span><span>锁：使用锁的机制尽可能的保证并发事务的隔离性，避免并发的不利影响。</span></p>
<p><span><span>l<span> </span></span></span><span>事务日志：事务日志记录着整个事务的所有操作步骤，必要的时候靠日志重新开始事务或者回滚事务。不管出现什么状况，哪怕是网络中断，机器断电，甚至是数据库引擎本身出问题了，通过事务日志都能保证事务的完整性。</span></p>
<p><span><span>l<span> </span></span></span><span>事务管理：保证一个事务的原子性和数据的一致性。一个事务开始后，它要么成功的完成，要么失败，回滚到事务没开始前的那个状态，事务开始做的所有修改都将复原。</span></p>
<h2><a name="_Toc167987834"><span><span>1.<span> </span></span></span><span>事务的模式</span></a></h2>
<p><span>控制事务的开始结束的时间点和事务的范围，有几种事务模式：</span></p>
<h3><a name="_Toc167987835"><span><span>1.1.</span></span><span>显式事务（</span></a><span><span>Explicit Transactions</span></span><span><span>）</span></span></h3>
<p><span>显式事务通过</span><span>sql</span><span>脚本的</span><span>BEGIN TRANSACTION</span><span>或者编程接口（</span><span>API</span><span>）的开始事务语句启动事务，以</span><span>sql</span><span>脚本的</span><span>COMMIT </span><span>或</span><span> ROLLBACK</span><span>语句提交或回滚事务，编程接口（</span><span>API</span><span>）的提交事务或回滚事务语句结束事务。都是通过显式的命令控制事务的开始和结束。</span></p>
<p><span>从事务开始到事务提交或者回滚是一个完整的事务周期，事务一旦开始，结果要么是提交，要么是回滚。</span></p>
<p><span>如果事务范围内发生错误，错误分为几种类型，不同类型的错误有不同的行为。</span></p>
<p><span><span>l<span> </span></span></span><span>严重错误</span></p>
<p><span>比如，客户端到服务端的网络中断了，或者客户的机器被关机了，数据引擎会被通知数据连接已中断，这样严重的错误数据引擎会自动在服务端回滚整个事务。</span></p>
<p><span><span>l<span> </span></span></span><span>运行时错误</span></p>
<p><span>语句之间的“</span><span>GO</span><span>”命令形成的区域为命令批次。数据引擎编译和执行语句是以批次为单位的。一次编译一个批次的命令，编译完成后执行这个批次的命令。存储过程是整个被一次编译的，所以一个存储过程内不分批次，整个过程就是一个批次。</span></p>
<p><span>大多数情况下，在一个批次中一条语句发生运行时错误，这个语句将被中止，同时同一批次的所有后续语句也不再执行，但同一批次前面已经执行的命令依然有效。但是可以使用了</span><span>try…catch</span><span>捕获错误，并进行相应处理，比如执行事务回滚命令。</span></p>
<p><span>有一些运行时错误，比如插入了一个主键重复的记录，只中止当前出错的这条语句，后续的语句照样继续执行。这类错误也能被</span><span>try…catch</span><span>捕获到。</span></p>
<p><span>为了保证整个事务中，任何语句出现错误都回滚整个事务，最简单的方法是在事务开始前设置</span><span>SET XACT_ABORT </span><span>为</span><span> ON</span><span>，这个设置指示数据引擎，在一个事务中遇到一个错误后，不再执行后续的事务，并回滚整个事务。</span></p>
<p><span><span>l<span> </span></span></span><span>编译错误</span></p>
<p><span>遇到编译错误时，错误语句所在的批次不被执行，并不会受</span><span>SET XACT_ABORT</span><span>设置的影响。</span></p>
<h3><a name="_Toc167987836"><span><span>1.2.</span></span><span>自动提交事务（</span></a><span><span>Autocommit Transactions</span></span><span><span>）</span></span></h3>
<p><span>这个模式是数据引擎的缺省模式，也是各种编程接口的事务缺省模式。每个单独的语句在完成后被提交，失败后被回滚，编程人员不需要指定任何命令。</span></p>
<p><span>每个单独的语句就是一个事务的单位，成功了就提交，这句语句执行错误就回滚这条语句，对其他语句的执行不产生影响。注意这里说的执行错误是运行时错误，如果语句本身有编译错误，比如</span><span>sql</span><span>语句的关键词拼写错误了，那么发生编译错误语句所在的那个批次的语句都将不被执行。比如：</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p><span>USE AdventureWorks;</span></p>
<p><span>GO</span></p>
<p><span>CREATE TABLE TestBatch (Cola INT PRIMARY KEY, Colb CHAR(3));</span></p>
<p><span>GO</span></p>
<p><span>INSERT INTO TestBatch VALUES (1, &#8216;aaa&#8217;);</span></p>
<p><span>INSERT INTO TestBatch VALUES (2, &#8216;bbb&#8217;);</span></p>
<p><span>INSERT INTO TestBatch VALUSE (3, &#8216;ccc&#8217;); &#8212; Syntax error.</span></p>
<p><span>GO</span></p>
<p><span>SELECT * FROM TestBatch; &#8212; Returns no rows.</span></p>
<p><span>GO</span></div>
</td>
</tr>
</tbody>
</table>
<p><span>上面这段</span><span>sql</span><span>中的第三个</span><span>insert</span><span>语句</span><span>values</span><span>关键字拼写错误，将导致编译错误，结果是跟这个语句在同一批次的所有三条</span><span>insert</span><span>语句都将不被执行。</span></p>
<p><span>如果上面第三个</span><span>insert</span><span>语句是这样的：</span></p>
<p><span>INSERT INTO TestBatch VALUES (1, &#8216;ccc&#8217;); &#8212; Duplicate key error.</span></p>
<p><span>这将产生一个运行时错误“重复的主键”，这条语句将被回滚，但是不影响前面两条</span><span>insert</span><span>语句。从这点可以看出，自动提交模式是每条单独的语句要么完成要么回滚，不影响其他语句的执行。</span></p>
<h3><a name="_Toc167987837"><span><span>1.3.</span></span><span>隐式事务（</span></a><span><span>Implicit Transactions</span></span><span><span>）</span></span></h3>
<p><span>在</span><span>SET IMPLICIT_TRANSACTIONS ON</span><span>命令之后的第一条语句开始，就开始一个新的事务，直到遇到</span><span>COMMIT </span><span>或</span><span> ROLLBACK</span><span>语句结束这个事务，下一个语句又是一个新的事务，同样直到遇到</span><span>COMMIT </span><span>或</span><span> ROLLBACK</span><span>语句结束这个事务。这样形成了一个事务链，直到</span><span>SET IMPLICIT_TRANSACTIONS OFF</span><span>结束隐式事务，回到默认的自动提交事务模式。</span></p>
<p><span>事务中的行为跟显式事务模式是一致的。</span></p>
<p><span>事务体现在</span><span>connection</span><span>的水平，一个</span><span>connection</span><span>具有事务模式，自动提交模式是</span><span>connection</span><span>的缺省事务模式，直到</span><span>BEGIN TRANSACTION</span><span>语句开始显式事务模式，或者隐式事务被</span><span>SET IMPLICIT_TRANSACTIONS ON</span><span>设置，连接的事务模式被置为显式或隐式事务模式，当显示事务被提交或者回滚，隐式事务被置为关闭后，这个连接的事务模式又被置为自动提交模式。</span></p>
<h2><a name="_Toc167987838"><span><span>2.<span> </span></span></span><span>事务的编程</span></a></h2>
<p><span>数据库的编程有两种方式，一种应用程序接口（</span><span>API</span><span>），包括</span><span>ODBC</span><span>、</span><span>ADO </span><span>、</span><span>ado.net</span><span>等等编程接口，一种是</span><span>Transact-SQL</span><span>脚本，典型的是存储过程。</span></p>
<h3><a name="_Toc167987839"><span><span>2.1.</span></span><span>Transact-SQL</span></a><span><span>脚本</span></span></h3>
<p><strong><span>BEGIN TRANSACTION </span></strong></p>
<p><span>标记显式连接事务的起始点。</span></p>
<p><strong><span>COMMIT TRANSACTION </span></strong><strong><span>或</span></strong><strong><span> COMMIT WORK </span></strong></p>
<p><span>如果没有遇到错误，可使用该语句成功地结束事务。该事务中的所有数据修改在数据库中都将永久有效。事务占用的资源将被释放。</span></p>
<p><strong><span>ROLLBACK TRANSACTION </span></strong><strong><span>或</span></strong><strong><span> ROLLBACK WORK </span></strong></p>
<p><span>用来回滚遇到错误的事务。该事务修改的所有数据都返回到事务开始时的状态。事务占用的资源将被释放。</span></p>
<h3><a name="_Toc167987840"><span><span>2.2.</span></span><span>ADO.NET</span></a><span><span>应用程序接口</span></span></h3>
<p><span>对</span><span> SqlConnection </span><span>对象使用</span><span> BeginTransaction </span><span>方法可以启动一个显式事务。若要结束事务，可以对</span><span> SqlTransaction </span><span>对象调用</span><span> Commit() </span><span>或</span><span> Rollback() </span><span>方法。</span></p>
<p><span>下面主要以在存储过程中使用事务的编程详加说明</span></p>
<p><span>使用事务的目的是保持一段</span><span>sql</span><span>语句执行的完整性，要么全部执行成功，只要有一条语句失败就能完全回滚，回到事务开始前的状态。</span></p>
<p><span>事务有起点，即通过</span><span>BEGIN TRANSACTION</span><span>启动一个事务，其后执行事务中的各个语句，最后要判断，全部语句执行都成功了，就用</span><span>COMMIT TRANSACTION</span><span>提交事务，把事务中执行的语句的结果固定下来；如果事务中有任何错误，要能捕获到错误，并执行</span><span>ROLLBACK TRANSACTION</span><span>回滚整个事务。</span></p>
<p><span>下面是一段示例代码：</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p><span>USE AdventureWorks;</span></p>
<p><span>BEGIN TRANSACTION;</span></p>
<p><span>BEGIN TRY</span></p>
<p><span><span> </span>&#8211; </span><span>产生一个违反约束的错误</span><span>.</span></p>
<p><span><span> </span>DELETE FROM Production.Product</span></p>
<p><span><span> </span>WHERE ProductID = 980;</span></p>
<p><span>END TRY</span></p>
<p><span>BEGIN CATCH</span></p>
<p><span><span> </span>SELECT </span></p>
<p><span><span> </span>ERROR_NUMBER() AS ErrorNumber,</span></p>
<p><span><span> </span>ERROR_SEVERITY() AS ErrorSeverity,</span></p>
<p><span><span> </span>ERROR_STATE() as ErrorState,</span></p>
<p><span><span> </span>ERROR_PROCEDURE() as ErrorProcedure,</span></p>
<p><span><span> </span>ERROR_LINE() as ErrorLine,</span></p>
<p><span><span> </span>ERROR_MESSAGE() as ErrorMessage;</span></p>
<p><span><span> </span>IF @@TRANCOUNT &gt; 0</span></p>
<p><span><span> </span>ROLLBACK TRANSACTION;</span></p>
<p><span>END CATCH;</span></p>
<p><span>IF @@TRANCOUNT &gt; 0</span></p>
<p><span><span> </span>COMMIT TRANSACTION;</span></div>
</td>
</tr>
</tbody>
</table>
<p><span>把事务中要执行的语句都放在</span><span>TRY</span><span>语句块中，保证所有语句产生错误都能被捕获到。如果事务中的语句一旦产生错误，事务中的后续语句不再被执行，直接跳到</span><span>CATCH</span><span>语句块执行，进行出错后的后续处理过程。</span></p>
<p><span>CATCH</span><span>语句块中的最主要的工作就是执行事务回滚语句，以回滚整个事务。也可以进行一些其他辅助性的工作，显示错误，记录错误等等。</span></p>
<p><span>如果事务中所有语句都没有出错，顺利执行完成，程序就跳过</span><span>CATCH</span><span>语句块，执行最后的</span><span>COMMIT TRANSACTION</span><span>提交事务。</span></p>
<p><span>经常看到有些人使用</span><span>@@error</span><span>来捕获错误，判断是否需要回滚事务，代码大概如下：</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div>
<p><span>BEGIN TRANSACTION;</span></p>
<p><span>Select xxx from yyyy;<span> </span>&#8211;</span><span>事务中的</span><span>sql</span><span>语句</span></p>
<p><span>……</span></p>
<p><span>If @@error &gt; 0</span></p>
<p><span><span> </span>ROLLBACK TRANSACTION;</span></p>
<p><span> Else</span></p>
<p><span><span> </span>COMMIT TRANSACTION;</span></div>
</td>
</tr>
</tbody>
</table>
<p><span>这里使用</span><span>@@error</span><span>来判断事务中所有的语句是否发生错误，并以此来决定是回滚事务，还是提交事务。实际上这么做是是十分错误的。</span></p>
<p><span>第一，</span><span>@@error</span><span>是针对每个</span><span>sql</span><span>语句执行结果，反映的是当前执行的语句出错状态，当执行到下一句，</span><span>@@error</span><span>又被重置以反应下一句语句的执行结果。所以用</span><span>@@error</span><span>来判断所有语句是否出错是不行的。</span></p>
<p><span>第二，</span><span>sql</span><span>语句的运行时错误有两类，一类是语句发生了错误，此语句被中止，但后续语句还能被继续执行，一类是语句发生错误后，一个命令批次中的后续的所有语句也不再被执行。当事务中的语句发生这种错误，那么放在最后的</span><span>If @@error &gt; 0</span><span>判断语句都不会有机会被执行了。<br />
</span></p>
<p><span>这样的做法可能导致很严重的后果：如果事务中有语句产生第一类的错误，后续语句都不被执行，原来设计的ROLLBACK TRANSACTION或COMMIT TRANSACTION都没有机会被执行，就是说被这个事务锁了的资源都将得不到释放，产生的后果是，如果这个事务对某些记录设置了共享锁，那这些记录再 也不能被修改，更惨的是如果这个事务对某些记录设置了排他锁，那么读取这些记录的语句一直会被堵塞，执行不下去了。程序也就死在那里了。</span></p>
<p>所以，在事务中用来捕获语句错误还是需要使用<span>try…catch</span><span>语句块。</span></p>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F14%2Fsql-server-2005-%25E5%2588%2586%25E9%25A1%25B5%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">sql server 2005 分页</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2008%2F10%2F03%2Fnet-making-gains-against-java-survey-says%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">.NET Making Gains Against Java, Survey Says</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2Fswitching-versions-of-the-aspnet-framework-the-fast-way%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Switching Versions of the ASP.Net Framework – The Fast Way</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Fjennal.cn%2F2009%2F04%2F15%2F%25E8%25BD%25ACiis-aspnet-11%25E4%25B8%258E20%25E5%2585%25B1%25E5%25AD%2598%2F&from=http%3A%2F%2Fjennal.cn%2F2009%2F03%2F20%2F%25E6%25B7%25B1%25E5%2585%25A5sql-server%25E4%25B8%25AD%25E7%259A%2584%25E4%25BA%258B%25E5%258A%25A1%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[转]IIS ASP.NET 1.1与2.0共存</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://jennal.cn/2009/03/20/%e6%b7%b1%e5%85%a5sql-server%e4%b8%ad%e7%9a%84%e4%ba%8b%e5%8a%a1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

