<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_My Program life</title><subtitle type="text">吴碧宇,Knightfire,Wubiyu,Google Doc</subtitle><id>http://feed.cnblogs.com/blog/u/27676/rss</id><updated>2011-07-26T03:50:33Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><generator>CNBlogs BlogServer</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/27676/rss"/><entry><id>http://www.cnblogs.com/wubiyu/archive/2011/07/26/2117035.html</id><title type="text">【转】c# 位操作</title><summary type="text">在C#中可以对整型运算对象按位进行逻辑运算。按位进行逻辑运算的意义是：依次取被运算对象的每个位，进行逻辑运算，每个位的逻辑运算结果是结果值的每个位。C#支持的位逻辑运算符如表2.9所示。算符号意义运算对象类型运算结果类型对象数实例~位逻辑非运算整型，字符型整型1~a&amp;amp;位逻辑与运算2a &amp;amp; b|位逻辑或运算2a | b^位逻辑异或运算2a ^ b&amp;lt;&amp;lt;位左移运算2a&amp;lt;&amp;lt;4&amp;gt;&amp;gt;位右移运算2a&amp;gt;&amp;gt;21、位逻辑非运算位逻辑非运算是单目的，只有一个运算对象。位逻辑非运算按位对运算对象的值进行非运算，即：如果某一位等于0，就将其转变为1；如果某</summary><published>2011-07-26T03:51:00Z</published><updated>2011-07-26T03:51:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2011/07/26/2117035.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2011/07/26/2117035.html"/><content type="html">&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;在C#中可以对整型运算对象按位进行逻辑运算。按位进行逻辑运算的意义是：依次取被运算对象的每个位，进行逻辑运算，每个位的逻辑运算结果是结果值的每个位。C#支持的位逻辑运算符如表2.9所示。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;div style="line-height: 22px;"&gt;&#xD;
&lt;table border="0" style="line-height: 22px; border-collapse: collapse;"&gt;&lt;colgroup style="line-height: 22px;"&gt;&lt;col style="line-height: 22px; width: 190px;" /&gt;&lt;col style="line-height: 22px; width: 231px;" /&gt;&lt;col style="line-height: 22px; width: 211px;" /&gt;&lt;col style="line-height: 22px; width: 219px;" /&gt;&lt;col style="line-height: 22px; width: 149px;" /&gt;&lt;col style="line-height: 22px; width: 264px;" /&gt;&lt;/colgroup&gt;&#xD;
&lt;tbody valign="top" style="line-height: 22px;"&gt;&#xD;
&lt;tr style="line-height: 22px; height: 55px;"&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; padding-left: 8px; padding-right: 8px; border-width: 1pt; border-color: initial; border-style: solid;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;算符号&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: 1pt; border-top-style: solid; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;意义&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: 1pt; border-top-style: solid; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;运算对象类型&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: 1pt; border-top-style: solid; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;运算结果类型&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: 1pt; border-top-style: solid; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;对象数&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: 1pt; border-top-style: solid; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;实例&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;tr style="line-height: 22px; height: 51px;"&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: 1pt; border-left-style: solid; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;~&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑&lt;strong style="line-height: 25px;"&gt;非&lt;/strong&gt;运算&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" rowspan="6" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;整型，字符型&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" rowspan="6" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;整型&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;1&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 33px; font-size: 16pt;"&gt;~a&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;tr style="line-height: 22px; height: 51px;"&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: 1pt; border-left-style: solid; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&amp;amp;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑&lt;strong style="line-height: 25px;"&gt;与&lt;/strong&gt;运算&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;2&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 33px; font-size: 16pt;"&gt;a &amp;amp; b&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;tr style="line-height: 22px; height: 51px;"&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: 1pt; border-left-style: solid; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;|&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑&lt;strong style="line-height: 25px;"&gt;或&lt;/strong&gt;运算&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;2&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 33px; font-size: 16pt;"&gt;a | b&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;tr style="line-height: 22px; height: 51px;"&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: 1pt; border-left-style: solid; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;^&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑&lt;strong style="line-height: 25px;"&gt;异或&lt;/strong&gt;运算&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;2&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 33px; font-size: 16pt;"&gt;a ^ b&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;tr style="line-height: 22px; height: 51px;"&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: 1pt; border-left-style: solid; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位&lt;strong style="line-height: 25px;"&gt;左移&lt;/strong&gt;运算&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;2&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 33px; font-size: 16pt;"&gt;a&amp;lt;&amp;lt;4&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;tr style="line-height: 22px; height: 51px;"&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: 1pt; border-left-style: solid; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位&lt;strong style="line-height: 25px;"&gt;右移&lt;/strong&gt;运算&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;2&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;td valign="center" style="line-height: 22px; border-bottom-width: 1pt; border-bottom-style: solid; border-left-width: medium; border-left-style: none; padding-left: 8px; padding-right: 8px; border-top-width: medium; border-top-style: none; border-right-width: 1pt; border-right-style: solid; border-color: initial;"&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-align: center; padding: 0px;"&gt;&lt;span style="line-height: 33px; font-size: 16pt;"&gt;a&amp;gt;&amp;gt;2&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;/tbody&gt;&#xD;
&lt;/table&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&lt;strong style="line-height: 25px;"&gt;1、位逻辑非运算&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑非运算是单目的，只有一个运算对象。位逻辑非运算按位对运算对象的值进行非运算，即：如果某一位等于0，就将其转变为1；如果某一位等于1，就将其转变为0。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;比如，对二进制的10010001进行位逻辑非运算，结果等于01101110，用十进制表示就是：&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;~145等于110；对二进制的01010101进行位逻辑非运算，结果等于10101010。用十进制表示就是~85等于176。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&lt;strong style="line-height: 25px;"&gt;2、位逻辑与运算&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑与运算将两个运算对象按位进行与运算。与运算的规则：1与1等于1，1与0等于0。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;比如：10010001（二进制）&amp;amp;11110000等于10010000（二进制）。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&lt;strong style="line-height: 25px;"&gt;3、位逻辑或运算&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑或运算将两个运算对象按位进行或运算。或运算的规则是：1或1等1，1或0等于1，&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;0或0等于0。比如10010001（二进制）| 11110000（二进制）等于11110001（二进制）。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&lt;strong style="line-height: 25px;"&gt;4、位逻辑异或运算&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位逻辑异或运算将两个运算对象按位进行异或运算。异或运算的规则是：1异或1等于0，&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;1异或0等于1，0异或0等于0。即：相同得0，相异得1。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;比如：10010001（二进制）^11110000（二进制）等于01100001（二进制）。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&lt;strong style="line-height: 25px;"&gt;5、位左移运算&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位左移运算将整个数按位左移若干位，左移后空出的部分0。比如：8位的byte型变量&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;byte a=0x65(即二进制的01100101),将其左移3位：a&amp;lt;&amp;lt;3的结果是0x27(即二进制的00101000)。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;&lt;strong style="line-height: 25px;"&gt;6、位右移运算&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;位右移运算将整个数按位右移若干位，右移后空出的部分填0。比如：8位的byte型变量&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;Byte a=0x65(既（二进制的01100101）)将其右移3位：a&amp;gt;&amp;gt;3的结果是0x0c(二进制00001100)。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;在进行位与、或、异或运算时，如果两个运算对象的类型一致，则运算结果的类型就是运算对象的类型。比如对两个int变量a和b做与运算，运算结果的类型还是int型。如果两个运算&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;对象的类型不一致，则C#要对不一致的类型进行类型转换，变成一致的类型，然后进行运算。&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: 22px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px;"&gt;&lt;span style="line-height: 25px; font-size: 12pt;"&gt;类型转换的规则同算术运算中整型量的转换则一致。&lt;/span&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/wubiyu/aggbug/2117035.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/wubiyu/archive/2011/07/26/2117035.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2011/07/01/2095256.html</id><title type="text">C#中调用Windows API时的数据类型对应关系</title><summary type="text">[转]C#中调用Windows API时的数据类型对应关系 BOOL=System.Int32BOOLEAN=System.Int32BYTE=System.UInt16CHAR=System.Int16COLORREF=System.UInt32DWORD=System.UInt32DWORD32=System.UInt32DWORD64=System.UInt64FLOAT=System.FloatHACCEL=System.IntPtrHANDLE=System.IntPtrHBITMAP=System.IntPtrHBRUSH=System.IntPtrHCONV=System.Int</summary><published>2011-07-01T02:04:00Z</published><updated>2011-07-01T02:04:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2011/07/01/2095256.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2011/07/01/2095256.html"/><content type="html">[转]C#中调用Windows API时的数据类型对应关系&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;BOOL=System.Int32&lt;br /&gt;BOOLEAN=System.Int32&lt;br /&gt;BYTE=System.UInt16&lt;br /&gt;CHAR=System.Int16&lt;br /&gt;COLORREF=System.UInt32&lt;br /&gt;DWORD=System.UInt32&lt;br /&gt;DWORD32=System.UInt32&lt;br /&gt;DWORD64=System.UInt64&lt;br /&gt;FLOAT=System.Float&lt;br /&gt;HACCEL=System.IntPtr&lt;br /&gt;HANDLE=System.IntPtr&lt;br /&gt;HBITMAP=System.IntPtr&lt;br /&gt;HBRUSH=System.IntPtr&lt;br /&gt;HCONV=System.IntPtr&lt;br /&gt;HCONVLIST=System.IntPtr&lt;br /&gt;HCURSOR=System.IntPtr&lt;br /&gt;HDC=System.IntPtr&lt;br /&gt;HDDEDATA=System.IntPtr&lt;br /&gt;HDESK=System.IntPtr&lt;br /&gt;HDROP=System.IntPtr&lt;br /&gt;HDWP=System.IntPtr&lt;br /&gt;HENHMETAFILE=System.IntPtr&lt;br /&gt;HFILE=System.IntPtr&lt;br /&gt;HFONT=System.IntPtr&lt;br /&gt;HGDIOBJ=System.IntPtr&lt;br /&gt;HGLOBAL=System.IntPtr&lt;br /&gt;HHOOK=System.IntPtr&lt;br /&gt;HICON=System.IntPtr&lt;br /&gt;HIMAGELIST=System.IntPtr&lt;br /&gt;HIMC=System.IntPtr&lt;br /&gt;HINSTANCE=System.IntPtr&lt;br /&gt;HKEY=System.IntPtr&lt;br /&gt;HLOCAL=System.IntPtr&lt;br /&gt;HMENU=System.IntPtr&lt;br /&gt;HMETAFILE=System.IntPtr&lt;br /&gt;HMODULE=System.IntPtr&lt;br /&gt;HMONITOR=System.IntPtr&lt;br /&gt;HPALETTE=System.IntPtr&lt;br /&gt;HPEN=System.IntPtr&lt;br /&gt;HRGN=System.IntPtr&lt;br /&gt;HRSRC=System.IntPtr	HSZ=System.IntPtr&lt;br /&gt;HWINSTA=System.IntPtr&lt;br /&gt;HWND=System.IntPtr&lt;br /&gt;INT=System.Int32&lt;br /&gt;INT32=System.Int32&lt;br /&gt;INT64=System.Int64&lt;br /&gt;LONG=System.Int32&lt;br /&gt;LONG32=System.Int32&lt;br /&gt;LONG64=System.Int64&lt;br /&gt;LONGLONG=System.Int64&lt;br /&gt;LPARAM=System.IntPtr&lt;br /&gt;LPBOOL=System.Int16[]&lt;br /&gt;LPBYTE=System.UInt16[]&lt;br /&gt;LPCOLORREF=System.UInt32[]&lt;br /&gt;LPCSTR=System.String&lt;br /&gt;LPCTSTR=System.String&lt;br /&gt;LPCVOID=System.UInt32&lt;br /&gt;LPCWSTR=System.String&lt;br /&gt;LPDWORD=System.UInt32[]&lt;br /&gt;LPHANDLE=System.UInt32&lt;br /&gt;LPINT=System.Int32[]&lt;br /&gt;LPLONG=System.Int32[]&lt;br /&gt;LPSTR=System.String&lt;br /&gt;LPTSTR=System.String&lt;br /&gt;LPVOID=System.UInt32&lt;br /&gt;LPWORD=System.Int32[]&lt;br /&gt;LPWSTR=System.String&lt;br /&gt;LRESULT=System.IntPtr&lt;br /&gt;PBOOL=System.Int16[]&lt;br /&gt;PBOOLEAN=System.Int16[]&lt;br /&gt;PBYTE=System.UInt16[]&lt;br /&gt;PCHAR=System.Char[]&lt;br /&gt;PCSTR=System.String&lt;br /&gt;PCTSTR=System.String&lt;br /&gt;PCWCH=System.UInt32&lt;br /&gt;PCWSTR=System.UInt32&lt;br /&gt;PDWORD=System.Int32[]&lt;br /&gt;PFLOAT=System.Float[]&lt;br /&gt;PHANDLE=System.UInt32&lt;br /&gt;PHKEY=System.UInt32&lt;br /&gt;PINT=System.Int32[]	ID=System.UInt32&lt;br /&gt;PLONG=System.Int32[]&lt;br /&gt;PLUID=System.UInt32&lt;br /&gt;PSHORT=System.Int16[]&lt;br /&gt;PSTR=System.String&lt;br /&gt;PTBYTE=System.Char[]&lt;br /&gt;PTCHAR=System.Char[]&lt;br /&gt;PTSTR=System.String&lt;br /&gt;PUCHAR=System.Char[]&lt;br /&gt;PUINT=System.UInt32[]&lt;br /&gt;PULONG=System.UInt32[]&lt;br /&gt;PUSHORT=System.UInt16[]&lt;br /&gt;PVOID=System.UInt32&lt;br /&gt;PWCHAR=System.Char[]&lt;br /&gt;PWORD=System.Int16[]&lt;br /&gt;PWSTR=System.String&lt;br /&gt;REGSAM=System.UInt32&lt;br /&gt;SC_HANDLE=System.IntPtr&lt;br /&gt;SC_LOCK=System.IntPtr&lt;br /&gt;SHORT=System.Int16&lt;br /&gt;SIZE_T=System.UInt32&lt;br /&gt;SSIZE_=System.UInt32&lt;br /&gt;TBYTE=System.Char&lt;br /&gt;TCHAR=System.Char&lt;br /&gt;UCHAR=System.Byte&lt;br /&gt;UINT=System.UInt32&lt;br /&gt;UINT32=System.UInt32&lt;br /&gt;UINT64=System.UInt64&lt;br /&gt;ULONG=System.UInt32&lt;br /&gt;ULONG32=System.UInt32&lt;br /&gt;ULONG64=System.UInt64&lt;br /&gt;ULONGLONG=System.UInt64&lt;br /&gt;USHORT=System.UInt16&lt;br /&gt;WORD=System.UInt16&lt;br /&gt;WPARAM=System.IntPtr&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;---------补充-----------&amp;gt;&lt;br /&gt;&lt;br /&gt;Wtypes.h 中的非托管类型&amp;nbsp;&amp;nbsp;&amp;nbsp; 非托管C 语言类型&amp;nbsp;&amp;nbsp;&amp;nbsp; 托管类名&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 说明&amp;nbsp; &lt;br /&gt;HANDLE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.IntPtr&amp;nbsp; 32 位&amp;nbsp; &lt;br /&gt;BYTE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Byte&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 位&amp;nbsp; &lt;br /&gt;SHORT                         short                    System.Int16   16 位  &lt;br /&gt;WORD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned short&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.UInt16&amp;nbsp; 16 位&amp;nbsp; &lt;br /&gt;INT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Int32&amp;nbsp;&amp;nbsp; 32 位&amp;nbsp; &lt;br /&gt;UINT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned int&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.UInt32&amp;nbsp; 32 位&amp;nbsp; &lt;br /&gt;LONG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; long&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Int32&amp;nbsp;&amp;nbsp; 32 位&amp;nbsp; &lt;br /&gt;BOOL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; long&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Int32&amp;nbsp;&amp;nbsp; 32 位&amp;nbsp; &lt;br /&gt;DWORD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned long&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.UInt32&amp;nbsp; 32 位&amp;nbsp; &lt;br /&gt;ULONG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned long&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.UInt32&amp;nbsp; 32 位&amp;nbsp; &lt;br /&gt;CHAR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Char&amp;nbsp;&amp;nbsp;&amp;nbsp; 用 ANSI 修饰。&amp;nbsp; &lt;br /&gt;LPSTR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String 或 System.StringBuilder 用 ANSI 修饰。&amp;nbsp; &lt;br /&gt;LPCSTR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Const char*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String 或 System.StringBuilder 用 ANSI 修饰。&amp;nbsp; &lt;br /&gt;LPWSTR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wchar_t*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String 或 System.StringBuilder 用 Unicode 修饰。&amp;nbsp; &lt;br /&gt;LPCWSTR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Const wchar_t*&amp;nbsp;&amp;nbsp;&amp;nbsp; System.String 或 System.StringBuilder 用 Unicode 修饰。&amp;nbsp; &lt;br /&gt;FLOAT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Float&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Single 32 位&amp;nbsp; &lt;br /&gt;DOUBLE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Double&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Double 64 位&lt;br /&gt;&lt;img src="http://www.cnblogs.com/wubiyu/aggbug/2095256.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/wubiyu/archive/2011/07/01/2095256.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2011/01/26/1945148.html</id><title type="text">全面理解javascript的caller,callee,call,apply概念[转载]</title><summary type="text">全面理解javascript的caller,callee,call,apply概念[转载]2006/10/23 11:31在提到上述的概念之前，首先想说说javascript中函数的隐含参数：argumentsArguments该对象代表正在执行的函数和调用它的函数的参数。[function.]arguments[n]参数function ：选项。当前正在执行的 Function 对象的名字。 n ：选项。要传递给 Function 对象的从0开始的参数值索引。说明Arguments是进行函数调用时，除了指定的参数外，还另外创建的一个隐藏对象。Arguments是一个类似数组但不是数组的对象，</summary><published>2011-01-26T02:07:00Z</published><updated>2011-01-26T02:07:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2011/01/26/1945148.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2011/01/26/1945148.html"/><content type="html">&lt;p&gt;&lt;span style="font-family: Arial; line-height: 25px; font-size: 12px; color: #717171;"&gt;&#xD;
&lt;div style="font-family: georgia, 宋体, arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 32px; color: #706666; font-weight: bold; overflow-x: hidden; overflow-y: hidden;" &gt;全面理解javascript的caller,callee,call,apply概念[转载]&lt;/div&gt;&#xD;
&lt;div style="font-family: georgia; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 9px; line-height: 18px; margin-top: 0.1em; margin-right: 0px; margin-bottom: 0.1em; margin-left: 0.5em; color: #7e7e7e;" &gt;2006/10/23 11:31&lt;/div&gt;&#xD;
&lt;/span&gt;&lt;/p&gt;&#xD;
&lt;table style="table-layout: fixed; width: 940px;"&gt;&#xD;
&lt;tbody&gt;&#xD;
&lt;tr&gt;&#xD;
&lt;td style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px;"&gt;&#xD;
&lt;div style="font-family: Arial; word-wrap: break-word; word-break: normal; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 13px; line-height: 20px; color: #706666; overflow-x: hidden; overflow-y: hidden; position: static;"  id="blog_text"&gt;&#xD;
&lt;p style="line-height: normal;"&gt;在提到上述的概念之前，首先想说说javascript中函数的隐含参数：arguments&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;Arguments&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;该对象代表正在执行的函数和调用它的函数的参数。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;[function.]arguments[n]&lt;br style="line-height: normal;" /&gt;参数function ：选项。当前正在执行的 Function 对象的名字。 n ：选项。要传递给 Function 对象的从0开始的参数值索引。&amp;nbsp;&lt;br style="line-height: normal;" /&gt;说明&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;Arguments是进行函数调用时，除了指定的参数外，还另外创建的一个隐藏对象。Arguments是一个类似数组但不是数组的对象，说它类似数组是因为其具有数组一样的访问性质及方式，可以由arguments[n]来访问对应的单个参数的值，并拥有数组长度属性length。还有就是arguments对象存储的是实际传递给函数的参数，而不局限于函数声明所定义的参数列表，而且不能显式创建 arguments 对象。arguments 对象只有函数开始时才可用。下边例子详细说明了这些性质:&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;&lt;br style="line-height: normal;" /&gt;//arguments 对象的用法。&lt;br style="line-height: normal;" /&gt;function ArgTest(a, b){&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var i, s = "The ArgTest function expected ";&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var numargs = arguments.length;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 获取被传递参数的数值。&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var expargs = ArgTest.length;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 获取期望参数的数值。&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (expargs &amp;lt; 2)&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += expargs + " argument. ";&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += expargs + " arguments. ";&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (numargs &amp;lt; 2)&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += numargs + " was passed.";&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += numargs + " were passed.";&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += "\n\n"&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i =0 ; i &amp;lt; numargs; i++){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 获取参数内容。&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s += "&amp;nbsp;&amp;nbsp; Arg " + i + " = " + arguments[i] + "\n";&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(s);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 返回参数列表。&lt;br style="line-height: normal;" /&gt;}&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;在此添加了一个说明arguments不是数组(Array类)的代码:&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;&lt;br style="line-height: normal;" /&gt;Array.prototype.selfvalue = 1;&lt;br style="line-height: normal;" /&gt;alert(new Array().selfvalue);&lt;br style="line-height: normal;" /&gt;function testAguments(){&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(arguments.selfvalue);&lt;br style="line-height: normal;" /&gt;}&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;运行代码你会发现第一个alert显示1，这表示数组对象拥有selfvalue属性，值为1，而当你调用函数testAguments时，你会发现显示的是&amp;ldquo;undefined&amp;rdquo;，说明了不是arguments的属性，即arguments并不是一个数组对象。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;caller&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; 返回一个对函数的引用，该函数调用了当前函数。&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; functionName.caller&amp;nbsp;&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; functionName 对象是所执行函数的名称。&lt;br style="line-height: normal;" /&gt;说明&lt;br style="line-height: normal;" /&gt;对于函数来说，caller 属性只有在函数执行时才有定义。如果函数是由顶层调用的，那么 caller 包含的就是 null 。如果在字符串上下文中使用 caller 属性，那么结果和 functionName.toString 一样，也就是说，显示的是函数的反编译文本。&lt;br style="line-height: normal;" /&gt;下面的例子说明了 caller 属性的用法：&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;// caller demo {&lt;br style="line-height: normal;" /&gt;function callerDemo() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (callerDemo.caller) {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var a= callerDemo.caller.toString();&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(a);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert("this is a top function");&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;}&lt;br style="line-height: normal;" /&gt;function handleCaller() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; callerDemo();&lt;br style="line-height: normal;" /&gt;}&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;callee&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;返回正被执行的 Function 对象，也就是所指定的 Function 对象的正文。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;[function.]arguments.callee&lt;br style="line-height: normal;" /&gt;可选项 function 参数是当前正在执行的 Function 对象的名称。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;说明&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;callee 属性的初始值就是正被执行的 Function 对象。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;callee 属性是 arguments 对象的一个成员，它表示对函数对象本身的引用，这有利于匿名&lt;br style="line-height: normal;" /&gt;函数的递归或者保证函数的封装性，例如下边示例的递归计算1到n的自然数之和。而该属性&lt;br style="line-height: normal;" /&gt;仅当相关函数正在执行时才可用。还有需要注意的是callee拥有length属性，这个属性有时候&lt;br style="line-height: normal;" /&gt;用于验证还是比较好的。arguments.length是实参长度，arguments.callee.length是&lt;br style="line-height: normal;" /&gt;形参长度，由此可以判断调用时形参长度是否和实参长度一致。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;示例&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;&lt;br style="line-height: normal;" /&gt;//callee可以打印其本身&lt;br style="line-height: normal;" /&gt;function calleeDemo() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(arguments.callee);&lt;br style="line-height: normal;" /&gt;}&lt;br style="line-height: normal;" /&gt;//用于验证参数&lt;br style="line-height: normal;" /&gt;function calleeLengthDemo(arg1, arg2) {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (arguments.length==arguments.callee.length) {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.alert("验证形参和实参长度正确！");&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert("实参长度：" +arguments.length);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert("形参长度： " +arguments.callee.length);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;}&lt;br style="line-height: normal;" /&gt;//递归计算&lt;br style="line-height: normal;" /&gt;var sum = function(n){&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; if (n &amp;lt;= 0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; return 1;&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; else&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return n ＋arguments.callee(n - 1)&lt;br style="line-height: normal;" /&gt;}&lt;br style="line-height: normal;" /&gt;比较一般的递归函数：&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;var sum = function(n){&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (1==n) return 1;&lt;br style="line-height: normal;" /&gt;else return n + sum (n-1);&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;调用时：alert(sum(100));&lt;br style="line-height: normal;" /&gt;其中函数内部包含了对sum自身的引用，函数名仅仅是一个变量名，在函数内部调用sum即相当于调用&lt;br style="line-height: normal;" /&gt;一个全局变量，不能很好的体现出是调用自身，这时使用callee会是一个比较好的方法。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;&lt;br style="line-height: normal;" /&gt;apply and call&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;它们的作用都是将函数绑定到另外一个对象上去运行，两者仅在定义参数方式有所区别：&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;apply(thisArg,argArray);&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;call(thisArg[,arg1,arg2&amp;hellip;] ]);&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;即所有函数内部的this指针都会被赋值为thisArg，这可实现将函数作为另外一个对象的方法运行的目的&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;apply的说明&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;如果 argArray 不是一个有效的数组或者不是 arguments 对象，那么将导致一个 TypeError。&lt;br style="line-height: normal;" /&gt;如果没有提供 argArray 和 thisArg任何一个参数，那么 Global 对象将被用作 thisArg，&amp;nbsp;&lt;br style="line-height: normal;" /&gt;并且无法被传递任何参数。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;call的说明&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisArg指定的新对象。&lt;br style="line-height: normal;" /&gt;如果没有提供 thisArg参数，那么 Global 对象被用作 thisArg&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;相关技巧：&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;应用call和apply还有一个技巧在里面，就是用call和apply应用另一个函数（类）以后，当前的&lt;br style="line-height: normal;" /&gt;函数（类）就具备了另一个函数（类）的方法或者是属性，这也可以称之为&amp;ldquo;继承&amp;rdquo;。看下面示例:&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;// 继承的演示&lt;br style="line-height: normal;" /&gt;function base() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.member = " dnnsun_Member";&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.method = function() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.alert(this.member);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;}&lt;br style="line-height: normal;" /&gt;function extend() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; base.call(this);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.alert(member);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; window.alert(this.method);&lt;br style="line-height: normal;" /&gt;}&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;上面的例子可以看出，通过call之后，extend可以继承到base的方法和属性。&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;顺便提一下，在javascript框架prototype里就使用apply来创建一个定义类的模式，&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;其实现代码如下：&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;var Class = {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; create: function() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return function() {&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.initialize.apply(this, arguments);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;}&lt;br style="line-height: normal;" /&gt;解析：从代码看,该对象仅包含一个方法：Create，其返回一个函数，即类。但这也同时是类的&lt;br style="line-height: normal;" /&gt;构造函数，其中调用initialize，而这个方法是在类创建时定义的初始化函数。通过如此途径，&lt;br style="line-height: normal;" /&gt;就可以实现prototype中的类创建模式&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;示例：&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;var vehicle=Class.create();&lt;br style="line-height: normal;" /&gt;vehicle.prototype={&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; initialize:function(type){&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.type=type;&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; showSelf:function(){&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert("this vehicle is "+ this.type);&lt;br style="line-height: normal;" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br style="line-height: normal;" /&gt;}&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;var moto=new vehicle("Moto");&lt;br style="line-height: normal;" /&gt;moto.showSelf();&lt;/p&gt;&#xD;
&lt;p style="line-height: normal;"&gt;更详细的关于prototype信息请到其官方网站查看。&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&lt;/td&gt;&#xD;
&lt;/tr&gt;&#xD;
&lt;/tbody&gt;&#xD;
&lt;/table&gt;&lt;img src="http://www.cnblogs.com/wubiyu/aggbug/1945148.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/wubiyu/archive/2011/01/26/1945148.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2010/11/23/1885824.html</id><title type="text">发几个小的测式软件</title><summary type="text">流控狗程序-下载反ARP程序-下载计算机急救中心-下载</summary><published>2010-11-23T11:59:00Z</published><updated>2010-11-23T11:59:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2010/11/23/1885824.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2010/11/23/1885824.html"/><content type="html">&lt;p&gt;流控狗程序-&lt;a href="http://files.cnblogs.com/wubiyu/%e6%b5%81%e6%8e%a7%e7%8b%97.rar"&gt;下载&lt;/a&gt;&lt;/p&gt;&#xD;
&lt;p&gt;反ARP程序-&lt;a href="http://files.cnblogs.com/wubiyu/%e5%8f%8dARP%e7%97%85%e6%af%92.rar"&gt;下载&lt;/a&gt;&lt;/p&gt;&#xD;
&lt;p&gt;计算机急救中心-&lt;a href="http://files.cnblogs.com/wubiyu/%e8%ae%a1%e7%ae%97%e6%9c%ba%e6%80%a5%e6%95%91%e4%b8%ad%e5%bf%83.rar"&gt;下载&lt;/a&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/wubiyu/aggbug/1885824.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/wubiyu/archive/2010/11/23/1885824.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2010/06/01/1748967.html</id><title type="text">關於 IE6/7 不支援 Element 自訂方法屬性繼承的可行解決方案</title><summary type="text">[转]關於 IE6/7 不支援 Element 自訂方法屬性繼承的可行解決方案来源[http://audi.tw/Blog/JavaScript/javascript.element.ie.asp] 由 prototype 談起 物件導向語言，支援「繼承」的概念，也就是父物件有的方法及屬性，物件本身也一應具備。於是設計人員可以直接在上層物件定義好一堆自己專屬或改 良的方法和屬性，這比設計副程式庫還...</summary><published>2010-06-01T03:41:00Z</published><updated>2010-06-01T03:41:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2010/06/01/1748967.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2010/06/01/1748967.html"/><content type="html">该文只有注册用户登录后才能阅读。&lt;a href='http://www.cnblogs.com/wubiyu/archive/2010/06/01/1748967.html' target='_blank'&gt;阅读全文&lt;/a&gt;。</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2010/05/17/1737420.html</id><title type="text">Vs2010 配置驱动开发环境</title><summary type="text">1、安装VS2010，安装WDK 7.0(DDK);2、新建VC++-&amp;gt;Empty Project3、打开Configuration Manager 并新建一个名称为&amp;#8220; dirver &amp;#8221;的Solution Configuration 并将&amp;#8220;dirver&amp;#8221; 设为Active Solution Configuration .4、打开View-&amp;gt...</summary><published>2010-05-17T08:06:00Z</published><updated>2010-05-17T08:06:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2010/05/17/1737420.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2010/05/17/1737420.html"/><content type="html">&lt;p&gt;1、安装VS2010，安装WDK 7.0(DDK);&lt;/p&gt;&lt;p&gt;2、新建VC++-&amp;gt;Empty Project&lt;br /&gt;&lt;/p&gt;&lt;p&gt;3、打开Configuration Manager&amp;nbsp; 并新建一个名称为&amp;#8220; dirver &amp;#8221;的Solution Configuration 并将&amp;#8220;dirver&amp;#8221; 设为Active Solution Configuration .&lt;br /&gt;&lt;/p&gt;&lt;p&gt;4、打开View-&amp;gt; property Manager。&lt;br /&gt;&lt;/p&gt;&lt;p&gt;5、在"dirver"&amp;nbsp; solution configuration 上点击右键，选择Add new property Sheet。取名为&amp;#8220;dirverProperty&amp;#8221;. 并对他进下以下设置。&lt;br /&gt;&lt;/p&gt;&lt;p&gt;5.1. C\C++ - General - Debug Information Format = Program Database (/Zi)&lt;br /&gt;5.2. C\C++ - Preprocessor - Preprocessor Definitions = _X86_ [add also DBG for Debug config]&lt;br /&gt;【WIN32;_DEBUG;_X86_;i386;STD_CALL;CONDITION_HANDLING;WIN32_LEAN_AND_MEAN;NT_UP;SRVDBG;DBG;_IDWBUILD;_WIN32_WINNT=0x0400;% (PreprocessorDefinitions)】&lt;br /&gt;5.3. C\C++ - Code Generation - Enable C++ Exceptions = No&lt;br /&gt;5.4. C\C++ - Code Generation - Basic Runtime Checks = Default&lt;br /&gt;5.5. C\C++ - Code Generation - Buffer Security Check = No (/GS-)&lt;br /&gt;5.6. C\C++ - Advanced - Calling Convention = __stdcall (/Gz)&lt;br /&gt;5.7. C\C++ - Advanced - Compile As = Compile as C Code (/TC) [if you are going to use plain C]&lt;br /&gt;5.8. Linker - General - Output File = $(OutDir)\$(ProjectName).sys&lt;br /&gt;5.9. Linker - General - Enable Incremental Linking = Default&lt;br /&gt;5.10. Linker - Input - Additional Dependencies = ntoskrnl.lib hal.lib $(NOINHERIT) [add here needed libs here e.g. ntoskrnl.lib hal.lib]&lt;br /&gt;【不知道上面是不是笔误，应该为：ntoskrnl.lib;hal.lib;%(AdditionalDependencies)】&lt;br /&gt;5.11. Linker - Input - Ignore All Default Libraries = Yes (/NODEFAULTLIB)&lt;br /&gt;5.12. Linker - Manifest File - Generate Manifest = No&lt;br /&gt;5.13. Linker - System - SubSystem = Native (/SUBSYSTEM:NATIVE)&lt;br /&gt;5.14. Linker - System - Driver = Driver (/DRIVER)&lt;br /&gt;5.15. Linker - Advanced - Entry Point = DriverEntry&lt;br /&gt;5.16. Linker - Advanced - Base Address = 0x10000&lt;br /&gt;5.17. Linker - Advanced - Randomized Base Address = Disable (/DYNAMICBASE:NO)&lt;br /&gt;【这个也是错误的：应该置空】&lt;br /&gt;5.18. Linker - Advanced - Data Execution Prevention (DEP) = Disable (/NXCOMPAT:NO)&lt;br /&gt;【这个也是错误的：应该置空】&lt;br /&gt;&lt;br /&gt;6. Config VC++ Directories&lt;br /&gt;6.1 Open Open up property manager by clicking on Menu View-&amp;gt;Property Manager.&lt;br /&gt;6.2 Expand the project node and then the Configuration|Platform nodes, you will see "Microsoft.cpp.&amp;lt;Platform&amp;gt;.users" file for each Configuration|Platform. These are the files &lt;br /&gt;&lt;br /&gt;for the global settings, similar to the old tools/Options/VC++ Directories.&lt;br /&gt;6.3 Multi-Select "Microsoft.cpp.&amp;lt;Platform&amp;gt;.users", right click and bring up the property page window&lt;br /&gt;6.4 In the property page window, click on "VC++ Directories" (for example) in the left pane, add new paths for the directories such as "Include Directories". separated by &lt;br /&gt;&lt;br /&gt;semicolons&lt;br /&gt;(eg:Include Directories config As:&lt;br /&gt;$(ddkroot)\INC&lt;br /&gt;$(ddkroot)\INC\WNET&lt;br /&gt;$(ddkroot)\INC\DDK\WNET&lt;br /&gt;Library Directories config As:&lt;br /&gt;$(ddkroot)\LIB\WNET\I386&lt;br /&gt;)&lt;br /&gt;6.5 Make sure to save the settings before shutting down Visual Studio.&lt;br /&gt;6.6 Re-launch Visual Studio and the new settings will be in effect.&lt;br /&gt;6.7 Note: If you would like to only change the settings for one project, you can right click on the project and bring up the property page. Change the settings for &amp;#8220;VC++ &lt;br /&gt;&lt;br /&gt;Directories&amp;#8221;, these settings will be persisted to the project file.&lt;br /&gt;七. OK. Have done. Now you can test it with simple code, e.g.:&lt;br /&gt;&lt;br /&gt;#include "ntddk.h"&lt;br /&gt;&lt;br /&gt;NTSTATUS&lt;br /&gt;DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;return STATUS_UNSUCCESSFUL;&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;特别说明：&lt;br /&gt;&amp;nbsp;&amp;nbsp; 1.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Visual Studio 2010 在智能设备开发方面只支持Windows Phone OS 7.0。如果你要为Windows CE 5.0和Windows Mobile 6.5开发应用程序，请安装Visual Studio 2008。&lt;br /&gt;&amp;nbsp;&amp;nbsp; 2.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 做驱动开发时，SDK的版本要和WDK的版本一致，即Win7 WDK要配Win7 SDK，否则会出现编译错误。VS2010里集成了Windows SDK 7.0A。&lt;br /&gt;&amp;nbsp;&amp;nbsp; 3.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 如果出现类似如下编译错误，解决方法是：拷贝C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sal.h，然后覆盖掉C:\WinDDK\7600.16385.1\inc\api\sal.h。&lt;br /&gt;&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing ')' before 'const'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2143: syntax error : missing '{' before 'const'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2059: syntax error : ','&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h(550): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(56): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(56): error C2085: '_ExceptionRecord' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(57): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(57): error C2085: '_EstablisherFrame' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(58): error C2085: '_Inout_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(58): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(58): error C2085: '_ContextRecord' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(59): error C2085: '_Inout_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(59): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(60): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(60): error C2085: '_DispatcherContext' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(104): error C2082: redefinition of formal parameter '_exception_code'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(105): error C2082: redefinition of formal parameter '_exception_info'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\excpt.h(106): error C2082: redefinition of formal parameter '_abnormal_termination'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(92): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2085: '_isctype_l' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2085: '_C' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2085: '_In_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2085: '_Type' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2085: '_In_opt_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2146: syntax error : missing ',' before identifier '_locale_t'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2146: syntax error : missing ',' before identifier '_Locale'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(94): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2086: 'int _Check_return_' : redefinition&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93) : see declaration of '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2085: '_isalpha_l' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2085: '_C' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2085: '_In_opt_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2146: syntax error : missing ',' before identifier '_locale_t'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2146: syntax error : missing ',' before identifier '_Locale'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(95): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(96): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2086: 'int _Check_return_' : redefinition&lt;br /&gt;&amp;nbsp;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93) : see declaration of '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2085: '_isupper_l' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2085: '_C' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2085: '_In_opt_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2146: syntax error : missing ',' before identifier '_locale_t'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2146: syntax error : missing ',' before identifier '_Locale'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(97): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(98): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2086: 'int _Check_return_' : redefinition&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93) : see declaration of '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2085: '_islower_l' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2085: '_C' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2085: '_In_opt_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2146: syntax error : missing ',' before identifier '_locale_t'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2146: syntax error : missing ',' before identifier '_Locale'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(99): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(100): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2086: 'int _Check_return_' : redefinition&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93) : see declaration of '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2085: '_isdigit_l' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2085: '_C' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2085: '_In_opt_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2146: syntax error : missing ',' before identifier '_locale_t'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2146: syntax error : missing ',' before identifier '_Locale'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(101): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(102): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2086: 'int _Check_return_' : redefinition&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93) : see declaration of '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2085: '_isxdigit_l' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2085: '_C' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2085: '_In_opt_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2146: syntax error : missing ',' before identifier '_locale_t'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2146: syntax error : missing ',' before identifier '_Locale'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(103): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(104): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2086: 'int _Check_return_' : redefinition&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93) : see declaration of '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2085: '_isspace_l' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2143: syntax error : missing ';' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2085: '_C' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2085: '_In_opt_' : not in formal parameter list&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2146: syntax error : missing ',' before identifier '_locale_t'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2146: syntax error : missing ',' before identifier '_Locale'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(105): error C2059: syntax error : ')'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(106): error C2061: syntax error : identifier '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(107): error C2086: 'int _Check_return_' : redefinition&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(93) : see declaration of '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(107): error C2054: expected '(' to follow '_Check_return_'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(107): error C2143: syntax error : missing ')' before 'type'&lt;br /&gt;C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ctype.h(107): fatal error C1003: error count exceeds 100; stopping compilation&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/wubiyu/aggbug/1737420.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/wubiyu/archive/2010/05/17/1737420.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2010/04/30/1725404.html</id><title type="text">美杜杉 主动防御最新版</title><summary type="text">美杜杉 2010 家庭版1、优化启动速度。2、全新有UI界面。3、更加智能的主动杀。4、全新主动防强攻击行为特征库。5、添加英文语 言包。6、更加详细的监控日记计录，让木码病毒无处藏身。软件界面图。详细功能请见:http://m25.mds110.com点击立即下载</summary><published>2010-04-30T15:27:00Z</published><updated>2010-04-30T15:27:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2010/04/30/1725404.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2010/04/30/1725404.html"/><content type="html">&lt;p&gt;美杜杉 2010 家庭版&lt;/p&gt;&#xD;
&lt;p&gt;1、优化启动速度。&lt;br /&gt;&#xD;
&lt;/p&gt;&#xD;
&lt;p&gt;2、全新有UI界面。&lt;/p&gt;&#xD;
&lt;p&gt;3、更加智能的主动杀。&lt;/p&gt;&#xD;
&lt;p&gt;4、全新主动防强攻击行为特征库。&lt;/p&gt;&#xD;
&lt;p&gt;5、添加英文语 言包。&lt;/p&gt;&#xD;
&lt;p&gt;6、更加详细的监控日记计录，让木码病毒无处藏身。&lt;br /&gt;&#xD;
&lt;/p&gt;&#xD;
&lt;p&gt;软件界面图。&lt;/p&gt;&#xD;
&lt;p&gt;&lt;img src="http://images.cnblogs.com/cnblogs_com/wubiyu/98645/r_t1.JPG" alt="界面" /&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;img src="http://images.cnblogs.com/cnblogs_com/wubiyu/98645/r_t2.JPG" alt="主界面" /&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;详细功能请见:&lt;a target="_blank" href="http://m25.mds110.com/"&gt;http://m25.mds110.com&lt;/a&gt;&amp;nbsp;&lt;a target="_blank" href="http://www.mds110.com/NewEndpInstall/25/MedusaSetup.exe"&gt;点击立即下载&lt;/a&gt; &lt;br /&gt;&#xD;
&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&#xD;
&lt;p&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/wubiyu/aggbug/1725404.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/wubiyu/archive/2010/04/30/1725404.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2010/04/25/1719689.html</id><title type="text">Asp.net 异步请求 IHttpAsyncHandler</title><summary type="text">This article assumes you're familiar with C#, ASP.NET, and MultithreadingLevel of Difficulty 1 2 3 SUMMARYFortunately for developers, threading in ASP.NET is a lot easier than it was in ASP. In this article, the author takes a look at threading in the ASP.NET HTTP pipeline, and explains how threads are managed efficiently without the involvement of the developer. The article considers how the common language runtime threadpool is used by ASP.NET to service requests, looks at the pooling me</summary><published>2010-04-24T19:14:00Z</published><updated>2010-04-24T19:14:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2010/04/25/1719689.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2010/04/25/1719689.html"/><content type="html">&lt;div &gt;Use Threads and Build Asynchronous Handlers in Your Server-Side Web Code&lt;/div&gt;&#xD;
&lt;div &gt;Fritz Onion&lt;/div&gt;&#xD;
&lt;div&gt;&lt;span &gt;&lt;font color="#26252a" face="Segoe UI"&gt;Code download available at: &lt;/font&gt;&lt;/span&gt;&lt;a href="http://download.microsoft.com/download/9/D/3/9D34806C-7708-459B-9170-EF11493AEF89/Threading.exe" target="_blank"&gt;&lt;font color="#0066dd"&gt;Threading.exe&lt;/font&gt;&lt;/a&gt; &lt;font color="#26252a"&gt;&lt;font face="Segoe UI"&gt;&lt;span &gt;(121 KB) &lt;/span&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;span&gt;&lt;a id="ctl00_MTContentSelector1_mainContentContainer_ctl01" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_ctl00|ctl00_MTContentSelector1_mainContentContainer_ctl01',this);" href="http://msdn.microsoft.com/zh-cn/magazine/cc164892(en-us).aspx" target="_blank"&gt;&lt;font color="#0066dd"&gt;Browse the Code Online&lt;/font&gt;&lt;/a&gt; &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div &gt;This article assumes you're familiar with C#, ASP.NET, and Multithreading&lt;/div&gt;&#xD;
&lt;div &gt;&lt;strong&gt;Level of Difficulty&lt;/strong&gt; &lt;span &gt;1 &lt;/span&gt;&lt;span &gt;&lt;strong&gt;&lt;font color="#ffffff"&gt;2 &lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span &gt;3 &lt;/span&gt;&lt;/div&gt;&#xD;
&lt;div &gt;SUMMARY&lt;/div&gt;&#xD;
&lt;div &gt;Fortunately for developers, threading in ASP.NET is a lot easier than it was in ASP. In this article, the author takes a look at threading in the ASP.NET HTTP pipeline, and explains how threads are managed efficiently without the involvement of the developer. The article considers how the common language runtime threadpool is used by ASP.NET to service requests, looks at the pooling mechanisms used for handlers, modules, and applications, and covers both IIS 5.0 and IIS 6.0 and how they differ in their approach to request processing and thread allocation. Finally, how and when to use asynchronous handlers is discussed for developers who still need to use threads in their own applications.&lt;/div&gt;&#xD;
&lt;div &gt;&lt;/div&gt;&lt;span &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;!-- ApplyClick with current id --&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; vertical-align: middle; border-left-width: 0px"  src="http://i.msdn.microsoft.com/Global/Images/clear.gif"  alt="" /&gt; &amp;nbsp;Contents &lt;/div&gt;&#xD;
&lt;div style="display: block" &gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S1" target="_blank"&gt;&lt;font color="#0066dd"&gt;Threading in ASP.NET&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S2" target="_blank"&gt;&lt;font color="#0066dd"&gt;Thread Dispatching in IIS 5.0 and 6.0&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S3" target="_blank"&gt;&lt;font color="#0066dd"&gt;The Need for Asynchrony&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S4" target="_blank"&gt;&lt;font color="#0066dd"&gt;Asynchronous Handlers&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S5" target="_blank"&gt;&lt;font color="#0066dd"&gt;Asynchronous Handler with a Delegate&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S6" target="_blank"&gt;&lt;font color="#0066dd"&gt;Asynchronous Handler with Custom Threads&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S7" target="_blank" s_oidt="0" s_oid="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S7"&gt;&lt;font color="#0066dd"&gt;Asynchronous Handler with a Custom Thread Pool&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S8" target="_blank"&gt;&lt;font color="#0066dd"&gt;Asynchronous Pages&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/zh-cn/magazine/cc164128(en-us).aspx#S9" target="_blank"&gt;&lt;font color="#0066dd"&gt;Conclusion&lt;/font&gt;&lt;/a&gt; &lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&#xD;
&lt;div &gt;In traditional ASP, developers faced more threading issues than they knew what to do with. Because ASP was built on top of COM, there were very specific rules about the threading requirements of objects. Objects used by pages needed to be apartment threaded for maximum efficiency. Conversely, objects living in Session and Application state needed to be context-agile and able to aggregate the freethreaded marshaler, as well as have their state protected against concurrent access.&lt;/div&gt;&#xD;
&lt;div &gt;If you look at the documentation for ASP.NET, however, you will find very little information about threading requirements. Does this mean that all threading issues are solved and that ASP.NET developers can live carefree lives building .aspx pages and Microsoft&amp;#174; .NET Framework classes without cluttering their minds with concurrency issues? Well, yes, in most cases it does.&lt;/div&gt;&#xD;
&lt;div &gt;In this article, I will explore the details of threading in the HTTP pipeline and how it efficiently manages threads without burdening the developer. I will also take a look at how ASP.NET uses the common language runtime (CLR) thread pool to service requests, the pooling mechanisms used for handlers, modules, and applications, and some of the differences in request processing and thread allocation between Microsoft Internet Information Services (IIS) 5.0 and IIS 6.0. For those developers who just don't feel complete if they don't use threads in their applications, I will also introduce asynchronous handlers and discuss how and when to use them.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S1" &gt;Threading in ASP.NET&lt;/div&gt;&#xD;
&lt;div &gt;To efficiently service multiple client requests, Web servers make extensive use of concurrency by launching multiple processes and/or spawning multiple threads to service requests and perform work. ASP.NET is no exception and uses multiple threads within each worker process to service requests. In spite of this fact, ASP.NET developers need not concern themselves with the multitude of issues that come with developing in a multithreaded environment. Page requests are always serviced on the same thread, and a distinct instance of the Page class is always created to service any new requests. Distinct instances of application and module objects are also used to service each request. It is important, however, to understand how threads are used to service requests so that you don't make incorrect assumptions about which objects in your applications may be accessed by concurrent threads.&lt;/div&gt;&#xD;
&lt;div &gt;To begin with, ASP.NET uses the process-wide CLR thread pool to service requests (for more background on the CLR thread pool, see the &lt;a href="http://msdn.microsoft.com/msdnmag/issues/03/06/net/default.aspx" target="_blank"&gt;&lt;font color="#0066dd"&gt;.NET column&lt;/font&gt;&lt;/a&gt; in this issue). The size of this pool is configurable in the processModel element of machine.config, and is set to a default of 25 worker threads and 25 I/O threads: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl03" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl03_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl03_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl03_code"  space="preserve"&gt;&amp;lt;processModel enable="true" &#xD;
              &amp;#8226;&amp;#8226;&amp;#8226;&#xD;
            maxWorkerThreads="25" &#xD;
            maxIoThreads="25" /&amp;gt;&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;Threads are processed differently depending whether you are using IIS 5.0 or IIS 6.0, which I will discuss shortly. For each request that comes in, a new instance of the appropriate HttpApplication-derived class is created, as are the associated modules for that app. To avoid reallocating apps and modules too often, each AppDomain maintains a pool of apps and modules. The maximum size of the app pool is the same as the size of the thread pool, so by default, up to 25 requests per worker process can be processed concurrently, each with its own app and module set. &lt;strong&gt;Figure 1&lt;/strong&gt; shows a snapshot in time of the ASP.NET worker process. In this scenario, there are two active apps in the worker process, each with a dedicated AppDomain. Each app is currently processing two requests, and each is using two threads from the CLR thread pool to service those requests.&lt;/div&gt;&#xD;
&lt;div &gt;&lt;img alt="" src="http://i.msdn.microsoft.com/cc164128.fig01(en-us).gif" /&gt; &#xD;
&lt;div &gt;Figure 1&lt;strong&gt;&amp;nbsp;Threading and Pooling in the HTTP Pipeline&amp;nbsp;&lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div &gt;Several aspects of this architecture may influence the way you construct your ASP.NET applications. First, the fact that applications and modules are instantiated multiple times means that you should never rely on adding fields or other states because they will not be shared across multiple requests, as you might think. Instead, use one of the many state repositories available in the pipeline, such as the application-wide cache, the session state bag, the appliction state bag, or the per-request Items collection of the HttpContext class. Additionally you can use static data if properly synchronized.&lt;/div&gt;&#xD;
&lt;div &gt;By default, most handlers created to service requests are not pooled. You can pool handlers and even control pooling on a per-handler basis through the IsReusable property of IHttpHandler, but the only handlers that are pooled implicitly are custom handlers that you write with no designated handler factory. The PageHandlerFactory class does not perform pooling, nor does the SimpleHandlerFactory class, which instantiates .ashx-defined handlers. Typically, therefore, each request is serviced by a freshly allocated instance of the appropriate handler class, which is discarded after the request completes.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S2" &gt;Thread Dispatching in IIS 5.0 and 6.0&lt;/div&gt;&#xD;
&lt;div &gt;Requests in IIS 5.0 are typically serviced over I/O threads, or threads performing asynchronous I/O because requests are dispatched to the worker process using asynchronous writes to a named pipe. When the request is serviced in the worker process, it will typically use the thread on which the asynchronous read was performed. The threads used to service requests in the worker process are drawn from the process-wide CLR thread pool, although thread pool threads tied to I/O completion ports incorrectly return false from the IsThreadPoolThread property of the Thread class, so don't count on that property.&lt;/div&gt;&#xD;
&lt;div &gt;Although requests are typically serviced on I/O threads in IIS 5.0, under heavy loads, some requests are passed off to normal worker threads from the pool, so both types of threads are used simultaneously. The default size of the CLR thread pool is 25, with separate limits for I/O threads and worker threads. You can change the upper number of threads allocated in the CLR thread pool by modifying the processModel element found in machine.config, as was shown earlier.&lt;/div&gt;&#xD;
&lt;div &gt;Things change dramatically with IIS 6.0 (which ships with Windows&amp;#174; Server 2003). To begin with, inetinfo.exe is no longer used to service HTTP requests (although it remains in place to service other protocols, like FTP). Instead, HTTP requests are queued in a kernel-mode service, http.sys, which takes care of dispatching each request to the appropriate application queue. In addition, IIS 6.0 supports application pools, which are groupings of applications that will share a single worker process, now named w3pwp.exe. Application pools give you the option of having as many distinct worker processes as you want on any given server, depending on how much you care about process isolation between your Web applications.&lt;/div&gt;&#xD;
&lt;div &gt;This paradigm changes the way requests are handled in ASP.NET. Instead of dispatching requests from inetinfo.exe to the ASP.NET worker process, http.sys directly queues each request in the appropriate process. Thus all requests are now serviced by worker threads drawn from the CLR thread pool and never on I/O threads. Contrary to comments found in machine.config on Windows Server 2003, the processModel element is still used to initialize the upper bound of the thread pool, although all other attributes are ignored as they are now stored in the IIS 6.0 metabase.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S3" &gt;The Need for Asynchrony&lt;/div&gt;&#xD;
&lt;div &gt;Many factors influence the scalability of a Web application. In general, any time multiple concurrent operations request exclusive access to a shared resource, the scalability of the system is jeopardized. High on the list of resources that are shared on a system is the CPU itself (or CPUs on a multiprocessor box). A server running ASP.NET has its CPU shared among concurrent requests by way of a thread pool. The purpose of the thread pool is to efficiently allocate CPU time for processing requests with an upper limit on the total number of threads allocated. This is an important restriction to have in place, as creating an unbounded number of threads can easily grind a system to a halt when a large number of requests are made concurrently.&lt;/div&gt;&#xD;
&lt;div &gt;However, in cases where threads from the thread pool are used to perform work that is not CPU-intensive (like making a request to a remote database or invoking a remote Web Service), it is possible to saturate the thread pool without high CPU utilization. In this scenario, the thread pool is in fact reducing the scalability of the system because requests may be delayed (or possibly rejected) even though the server was not busy processing other requests.&lt;/div&gt;&#xD;
&lt;div &gt;As an example of swamping the thread pool, consider the following ASP.NET page, slow.aspx, that artificially delays its response by two seconds (with non-CPU-bound activity) and prints out the thread on which it was serviced: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl05" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl05_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl05_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl05_code"  space="preserve"&gt;&amp;lt;!-- File: slow.aspx --&amp;gt;&#xD;
&amp;lt;%@ Page Language="C#" %&amp;gt;&#xD;
&amp;lt;%@ Import Namespace="System.Reflection" %&amp;gt;&#xD;
&amp;lt;%@ Import Namespace="System.Threading" %&amp;gt;&#xD;
&#xD;
&amp;lt;script runat="server"&amp;gt;&#xD;
  protected void Page_Load(object src, EventArgs e)&#xD;
  {&#xD;
    System.Threading.Thread.Sleep(2000);&#xD;
    Response.Output.Write("SlowResponse, threadid={0}",&#xD;
                    AppDomain.GetCurrentThreadId());&#xD;
  }&#xD;
&amp;lt;/script&amp;gt;&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&#xD;
&lt;div &gt;Another ASP.NET page, fast.aspx, is nearly identical, except that it does not sleep for the two seconds that slow.aspx does: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl06" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl06_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl06_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl06_code"  space="preserve"&gt;&amp;lt;!-- File: fast.aspx --&amp;gt;&#xD;
&amp;lt;%@ Page Language="C#" %&amp;gt;&#xD;
&amp;lt;%@ Import Namespace="System.Reflection" %&amp;gt;&#xD;
&#xD;
&amp;lt;script runat="server"&amp;gt;&#xD;
  protected void Page_Load(object src, EventArgs e)&#xD;
  {&#xD;
    Response.Output.Write("FastResponse, threadid={0}",&#xD;
                    AppDomain.GetCurrentThreadId());&#xD;
  }&#xD;
&amp;lt;/script&amp;gt;&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&#xD;
&lt;div &gt;Using the Web Application Stress tool against a server hosting these two pages, you can test the average response time under heavy request traffic. An initial test issuing requests on 100 concurrent threads from a separate client machine to only the fast.aspx page results in an average response time of 0.0824 seconds, servicing 52,190 requests during a one-minute time interval. Running the client against both fast.aspx and slow.aspx, however, reduces the average response time for fast.aspx requests to 4.47 seconds (and slow.aspx is 6.54 seconds), with the total number of requests serviced in one minute reduced to 1062.&lt;/div&gt;&#xD;
&lt;div &gt;While the numbers are dramatically different across the board, the most disturbing result is that it took more than four seconds on average to serve fast.aspx, which you know takes very little time to process. Although contrived, this example shows the worst case scenario when you have pages that are relatively slow to serve fighting for the same request threads that more responsive pages contend for&amp;#8212;a dramatic increase in response times. If the slow pages in your application are sluggish due to intensive CPU usage, there is not much you can do about it except to throw in more hardware. If, however, the slow pages in your application are slow because they are waiting on non-CPU-bound operations to complete, then the problem is not the lack of CPU power, but the fact that slow requests are saturating the thread pool so that other requests must be queued until a thread is released.&lt;/div&gt;&#xD;
&lt;div &gt;You have a few options if you discover that your system's scalability is being adversely affected by the ASP.NET thread pool. You could change the upper limit of the thread pool. As you have seen, the default upper limit is set to 25 worker threads and 25 I/O threads. Of course, increasing the upper bound in the thread pool is a somewhat coarse-grained solution to the problem. If you can find the magic number that keeps your CPU utilization high and only delays or denies requests when the server is truly too busy to process more requests, you are very fortunate. The number of threads necessary to keep the server truly busy is not static, but will fluctuate based on factors like demand and process complexity.&lt;/div&gt;&#xD;
&lt;div &gt;Another potential solution is to carefully identify the requests in your system that take longer to complete and perform non-CPU-bound operations and to allocate distinct threads to service them, freeing up the original thread pool thread to service additional requests. This brings me to asynchronous handlers.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S4" &gt;Asynchronous Handlers&lt;/div&gt;&#xD;
&lt;div &gt;While most ASP.NET pages and handlers are serviced synchronously on threads drawn from the process-wide thread pool, it is possible to create handlers (and even pages) that service requests asynchronously. Asynchronous handlers implement the IHttpAsyncHandler interface, which derives from IHttpHandler implemented by synchronous handlers: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl07" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl07_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl07_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl07_code"  space="preserve"&gt;public interface IHttpAsyncHandler : IHttpHandler&#xD;
{&#xD;
  IAsyncResult BeginProcessRequest(HttpContext ctx,&#xD;
                                   AsyncCallback cb, &#xD;
                                   object obj);&#xD;
  void EndProcessRequest(IAsyncResult ar);&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&#xD;
&lt;div &gt;Handlers that implement this interface must implement two additional methods besides the standard methods of IHttpHandler. The first, BeginProcessRequest, is called by the application class instead of directly calling the ProcessRequest. It is then up to the handler to launch a new thread to process the request and then immediately return from the BeginProcessRequest method, passing back a reference to a valid IAsyncResult instance so that the runtime knows the operation is complete. The other method, EndProcessRequest, is called when the request processing is complete and can be used to clean up any allocated resources if necessary.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S5" &gt;Asynchronous Handler with a Delegate&lt;/div&gt;&#xD;
&lt;div &gt;If you have done any work with asynchronous execution in the .NET Framework, you know that the simplest and most often recommended way to perform work asynchronously is to use asynchronous delegate invocation. Invoking a delegate asynchronously by calling BeginInvoke implicitly uses a thread from the process-wide thread pool to execute the delegate function. Implementing an asynchronous handler using asynchronous delegate invocation is actually quite straightforward, as shown in &lt;strong&gt;Figure 2&lt;/strong&gt;.&lt;/div&gt;&lt;span&gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;!-- ApplyClick with current id --&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; vertical-align: middle; border-left-width: 0px"  src="http://i.msdn.microsoft.com/Global/Images/clear.gif"  alt="" /&gt; &amp;nbsp;Figure&amp;nbsp;2&amp;nbsp;HTTP Handler Implementation &lt;/div&gt;&#xD;
&lt;div style="display: block" &gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl30_ctl00_ctl00" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl30_ctl00_ctl00_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl30_ctl00_ctl00_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl30_ctl00_ctl00_code"  space="preserve"&gt;&amp;lt;!-- File: AsyncDelegate.ashx --&amp;gt;&#xD;
&amp;lt;%@ WebHandler Language="C#" &#xD;
     %&amp;gt;&#xD;
&#xD;
using System;&#xD;
using System.Web;&#xD;
using System.Threading;&#xD;
using System.Diagnostics;&#xD;
using System.Reflection;&#xD;
&#xD;
namespace EssentialAspDotNet.HttpPipeline&#xD;
{&#xD;
  public delegate void ProcessRequestDelegate(HttpContext ctx);&#xD;
&#xD;
  public class AsyncHandler : IHttpAsyncHandler&#xD;
  { &#xD;
    public void ProcessRequest(HttpContext ctx)&#xD;
    {&#xD;
       System.Threading.Thread.Sleep(2000);&#xD;
       ctx.Response.Output.Write(&#xD;
                    "AsyncDelegate, threaded={0}",&#xD;
                    AppDomain.GetCurrentThreadId());&#xD;
    }&#xD;
    &#xD;
    public bool IsReusable&#xD;
    {&#xD;
      get { return true;}&#xD;
    }&#xD;
&#xD;
    public IAsyncResult BeginProcessRequest(HttpContext ctx, &#xD;
                AsyncCallback cb, object obj)&#xD;
    {&#xD;
      ProcessRequestDelegate prg = &#xD;
               new ProcessRequestDelegate(ProcessRequest);&#xD;
      // Fire-and-forget&#xD;
      return prg.BeginInvoke(ctx, cb, obj);&#xD;
    }&#xD;
&#xD;
    public void EndProcessRequest(IAsyncResult ar)&#xD;
    {&#xD;
    }&#xD;
  }&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&#xD;
&lt;div &gt;My implementation of IHttpAsyncHandler.BeginProcessRequest calls BeginInvoke on an instance of my ProcessRequestDelegate which has been initialized with a reference to my ProcessRequest method. This has the effect of executing ProcessRequest on a separate thread, distinct from the request thread.&lt;/div&gt;&#xD;
&lt;div &gt;Running the same stress test I performed earlier with my slow.aspx page, this time using my new asyncDelegate.ashx handler instead of fast.aspx, produces the following results. The average response time for fast.aspx is 4.14 seconds and 7.86 seconds for asyncDelegate.ashx, with the total number of serviced requests at 957.&lt;/div&gt;&#xD;
&lt;div &gt;Disappointingly, the response time did not really improve for requests made to fast.aspx. The reason for this is that asynchronous delegate invocation completely defeats the purpose of building an asynchronous handler because it draws from the same process-wide CLR thread pool that ASP.NET uses to service requests. While the primary request thread is indeed returned to the thread pool, another thread is taken out to perform the asynchronous delegate execution, which means that there is a net gain of zero threads for servicing additional requests, rendering the handler useless. You will run into the same problem if you use ThreadPool.QueueUserWorkItem to perform the asynchronous request processing because it also draws threads from the same process-wide CLR thread pool.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S6" &gt;Asynchronous Handler with Custom Threads&lt;/div&gt;&#xD;
&lt;div &gt;To build a truly effective asynchronous handler, you must spawn an additional thread by hand in response to BeginProcessRequest. There are three important aspects to building a successful asynchronous handler. First, construct a class that supports IAsyncResult to return from BeginProcessRequest. Then, spawn the thread to perform your request processing asynchronously. Finally, notify ASP.NET that you are finished processing the request and are ready to return the response.&lt;/div&gt;&#xD;
&lt;div &gt;I will begin the construction of an asynchronous handler by building a class that supports IAsyncResult. This class is going to be returned from the call to BeginProcessRequest, and it will later be passed into my implementation of EndProcessRequest, so among other things, it is a useful place to store request-specific state that I may need to use during the processing of a request. The complete IAsyncResult interface to be implemented is shown here: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl10" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl10_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl10_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl10_code"  space="preserve"&gt;public interface IAsyncResult&#xD;
{&#xD;
  public object     AsyncState             { get; }&#xD;
  public bool       CompletedSynchronously { get; }&#xD;
  public bool       IsCompleted            { get; }&#xD;
  public WaitHandle AsyncWaitHandle        { get; }&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&#xD;
&lt;div &gt;In this example, I'll store a reference to the HttpContext object associated with the request, a reference to the AsyncCallback delegate passed into BeginProcessRequest (which I'll later invoke to complete the request), and a generic object reference for extra data that may be used by the caller of BeginProcessRequest. The other element that must be implemented in this class is a synchronization object that threads can wait on to be signaled when the operation completes. I will use the common technique of supplying a ManualResetEvent that fires when my request is complete, but allocate it only if someone requests it. Finally, my class will have a convenience method called CompleteRequest, which will trigger the ManualResetEvent if it was created, invoke the AsyncCallback delegate, and set the IsCompleted flag to true. The complete class definition for AsyncRequestState is shown in &lt;strong&gt;Figure 3&lt;/strong&gt;.&lt;/div&gt;&lt;span&gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;!-- ApplyClick with current id --&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; vertical-align: middle; border-left-width: 0px"  src="http://i.msdn.microsoft.com/Global/Images/clear.gif"  alt="" /&gt; &amp;nbsp;Figure&amp;nbsp;3&amp;nbsp;AsyncRequestState Class Definition &lt;/div&gt;&#xD;
&lt;div style="display: block" &gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl32_ctl00_ctl00" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl32_ctl00_ctl00_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl32_ctl00_ctl00_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl32_ctl00_ctl00_code"  space="preserve"&gt;// From file: AsyncThread.ashx&#xD;
class AsyncRequestState : IAsyncResult&#xD;
{&#xD;
  public AsyncRequestState(HttpContext ctx, &#xD;
                           AsyncCallback cb, &#xD;
                           object extraData )&#xD;
  {&#xD;
    _ctx = ctx;&#xD;
    _cb = cb;&#xD;
    _extraData = extraData;&#xD;
  }&#xD;
        &#xD;
  internal HttpContext _ctx;&#xD;
  internal AsyncCallback _cb;&#xD;
  internal object _extraData;&#xD;
  private bool _isCompleted = false;&#xD;
  private ManualResetEvent _callCompleteEvent = null;&#xD;
&#xD;
  internal void CompleteRequest()&#xD;
  {&#xD;
    _isCompleted = true;&#xD;
    lock (this)&#xD;
    {&#xD;
      if (_callCompleteEvent != null)&#xD;
        _callCompleteEvent.Set();&#xD;
    }&#xD;
    // if a callback was registered, invoke it now&#xD;
    if (_cb != null)&#xD;
      _cb(this);&#xD;
  }&#xD;
        &#xD;
  // IAsyncResult interface property implementations&#xD;
  public object AsyncState           &#xD;
  { get { return(_extraData);   } }&#xD;
  public bool CompletedSynchronously &#xD;
  { get { return(false);        } }&#xD;
  public bool IsCompleted            &#xD;
  { get { return(_isCompleted); } }&#xD;
  public WaitHandle AsyncWaitHandle&#xD;
  {&#xD;
    get&#xD;
    {&#xD;
      lock( this )&#xD;
      {&#xD;
        if( _callCompleteEvent == null )&#xD;
        _callCompleteEvent = new ManualResetEvent(false);&#xD;
      &#xD;
        return _callCompleteEvent;&#xD;
      }&#xD;
    }&#xD;
  }&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&#xD;
&lt;div &gt;The next step is to spawn a new thread to process my request. The method I call on this new thread will need access to the state I cached in the AsyncRequestState class just shown. Unfortunately, the ThreadStart delegate used to spawn new threads in the .NET Framework does not take any parameters. To get around this, I create another class with the necessary state cached as data members (in this case, simply a reference to the AsyncRequestState object for this request) and with an instance method that can be used to initialize the ThreadStart delegate. This class, called AsyncRequest, is shown in &lt;strong&gt;Figure 4&lt;/strong&gt;. Note that the ProcessRequest method I define in this class is the method that will be called from the manually created thread, and when it completes, it signals that the request processing is complete by invoking CompleteRequest on the AsyncRequestState object.&lt;/div&gt;&lt;span&gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;!-- ApplyClick with current id --&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; vertical-align: middle; border-left-width: 0px"  src="http://i.msdn.microsoft.com/Global/Images/clear.gif"  alt="" /&gt; &amp;nbsp;Figure&amp;nbsp;4&amp;nbsp;AsyncRequest &lt;/div&gt;&#xD;
&lt;div style="display: block" &gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl33_ctl00_ctl00" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl33_ctl00_ctl00_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl33_ctl00_ctl00_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl33_ctl00_ctl00_code"  space="preserve"&gt;// From file: AsyncThread.ashx&#xD;
class AsyncRequest&#xD;
{&#xD;
  private AsyncRequestState _asyncRequestState;&#xD;
&#xD;
  public AsyncRequest(AsyncRequestState ars)&#xD;
  {&#xD;
    _asyncRequestState = ars;&#xD;
  }&#xD;
    &#xD;
  public void ProcessRequest()&#xD;
  {&#xD;
    // This is where the non-cpu-bound activity would take place, such as&#xD;
    // accessing a Web Service, polling a slow piece of hardware, or &#xD;
    // performing a lengthy database operation. I put the thread to sleep &#xD;
    // for two seconds to simulate a lengthy operation.&#xD;
    Thread.Sleep(2000);&#xD;
      &#xD;
    _asyncRequestState._ctx.Response.Output.Write(&#xD;
            "AsyncThread, {0}", &#xD;
            AppDomain.GetCurrentThreadId());&#xD;
&#xD;
    // tell asp.net I am finished processing this request&#xD;
    _asyncRequestState.CompleteRequest();&#xD;
  }&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&#xD;
&lt;div &gt;Finally, I am ready to build the asynchronous handler class itself. This class, which I have called AsyncHandler, must implement all of the methods of the IHttpAsyncHandler interface shown earlier, which derives from IHttpHandler for a total of four methods. The ProcessRequest method is not used and will never be called because I implement BeginProcessRequest. In BeginProcessRequest, I create a new instance of the AsyncRequestState class, initializing it with the HttpContext object, the AsyncCallback delegate, and the generic object reference each passed in as parameters. I then prepare a new AsyncRequest object, initialized with the freshly created AsyncRequestState object, and launch a new thread. The implementation of EndProcessRequest will not do anything in this example, but it can be used in general to perform any cleanup or last-minute response additions. The AsyncHandler class definition is shown in &lt;strong&gt;Figure 5&lt;/strong&gt;.&lt;/div&gt;&lt;span&gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;!-- ApplyClick with current id --&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; vertical-align: middle; border-left-width: 0px"  src="http://i.msdn.microsoft.com/Global/Images/clear.gif"  alt="" /&gt; &amp;nbsp;Figure&amp;nbsp;5&amp;nbsp;AsyncHandler Class Definition &lt;/div&gt;&#xD;
&lt;div style="display: block" &gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl34_ctl00_ctl00" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl34_ctl00_ctl00_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl34_ctl00_ctl00_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl34_ctl00_ctl00_code"  space="preserve"&gt;// From file: AsyncThread.ashx&#xD;
public class AsyncHandler : IHttpAsyncHandler&#xD;
{ &#xD;
  public void ProcessRequest(HttpContext ctx)&#xD;
  {&#xD;
    // not used&#xD;
  }&#xD;
&#xD;
  public bool IsReusable&#xD;
  {&#xD;
    get { return false;}&#xD;
  }&#xD;
&#xD;
  public IAsyncResult BeginProcessRequest(HttpContext ctx, &#xD;
                                          AsyncCallback cb, &#xD;
                                          object obj)&#xD;
  {&#xD;
    AsyncRequestState reqState = &#xD;
                      new AsyncRequestState(ctx, cb, obj);&#xD;
    AsyncRequest ar = new AsyncRequest(reqState);&#xD;
    ThreadStart ts = new ThreadStart(ar.ProcessRequest);&#xD;
    Thread t = new Thread(ts);&#xD;
    t.Start();&#xD;
  &#xD;
    return reqState;&#xD;
  }&#xD;
&#xD;
  public void EndProcessRequest(IAsyncResult ar)&#xD;
  {&#xD;
    // This will be called on the manually created thread in response to &#xD;
    // calling the ASP.NET AsyncCallback delegate once the request has&#xD;
    // completed processing. The incoming IAsyncResult parameter will be &#xD;
    // a reference to the AsyncRequestState class, so the Context can be&#xD;
    // accessed through that class. Note - you *cannot* access the &#xD;
    // current context using the HttpContext.Current property, as you are &#xD;
    // running on your own thread which has not been initialized with a &#xD;
    // context reference.&#xD;
    AsyncRequestState ars = ar as AsyncRequestState;&#xD;
    if (ars != null)&#xD;
    {&#xD;
     // here you could perform some cleanup, write something else to the&#xD;
     // Response, or whatever else you need to do&#xD;
    }&#xD;
  }&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&#xD;
&lt;div &gt;When I build this handler and register it as an endpoint, as I did with the earlier handlers, it will successfully process requests asynchronously from the calling request thread of ASP.NET. &lt;strong&gt;Figure 6&lt;/strong&gt; shows the sequence of events that will take place when a request mapped onto the asynchronous handler is made. First the application class sees that my handler implements IHttpAsyncHandler, so instead of calling the synchronous ProcessRequest method, it invokes BeginProcessRequest on the handler, passing in the current context and an asynchronous callback delegate for completion call back. The handler then creates a new AsyncRequestState object, initialized with the parameters passed into BeginProcessRequest. Next, the handler creates a new AsyncRequest object, initialized with the AsyncRequestState object, and launches a new thread using the AsyncRequest.ProcessRequest method as the entry point. The handler then returns the AsyncRequestState object back to the application object and the calling thread is returned to the thread pool while the hand-created thread continues processing the request.&lt;/div&gt;&#xD;
&lt;div &gt;&lt;img alt="" src="http://i.msdn.microsoft.com/cc164128.fig06(en-us).gif" /&gt; &#xD;
&lt;div &gt;Figure 6&lt;strong&gt;&amp;nbsp;Async Handler Operation Phase 1&amp;nbsp;&lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div &gt;Once the ProcessRequest method of the AsyncRequest object is finished performing its lengthy tasks, it calls the CompleteRequest method of the AsyncRequestState class. This in turn will fire the AsyncCallback delegate originally passed into the BeginProcessRequest method, signaling that the response is prepared and ready for return. The first thing the AsyncCallback delegate will do is call the EndProcessRequest method on the asynchronous handler class. Once that returns, it will trigger the completion of the request by sending back the prepared response. All of this processing happens on the secondary thread that I created in the handler, not on a thread pool thread. &lt;strong&gt;Figure 7&lt;/strong&gt; shows the steps involved in completing the request to the asynchronous handler.&lt;/div&gt;&#xD;
&lt;div &gt;&lt;img alt="" src="http://i.msdn.microsoft.com/cc164128.fig07(en-us).gif" /&gt; &#xD;
&lt;div &gt;Figure 7&lt;strong&gt;&amp;nbsp;Async Handler Operation Phase 2&amp;nbsp;&lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div &gt;When I ran the same stress test I performed earlier with the slow.aspx page, this time using the new AsyncThread.ashx handler instead of AsyncDelegate.aspx, the following results are produced. The average response time for fast.aspx is .012 seconds and 2.014 seconds for AsyncThread.ashx, with the total number of serviced requests at 6132.&lt;/div&gt;&#xD;
&lt;div &gt;The average response time for requests made to fast.aspx is much improved because the thread pool is not tied up servicing requests to the slow handler.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S7" &gt;Asynchronous Handler with a Custom Thread Pool&lt;/div&gt;&#xD;
&lt;div &gt;There is one remaining problem with this asynchronous handler implementation&amp;#8212;it has the potential to create an unbounded number of threads. If a large number of requests are made to the asynchronous handler, all of which take a significant amount of time to service, then you could easily end up creating more threads than the underlying operating system can handle. To deal with this, I need to provide a secondary thread pool to service the requests in a bounded fashion. Details of creating custom thread pools are beyond the scope of this article, but a full example written in C# by Mike Woodring is available for download at &lt;a href="http://www.bearcanyon.com/dotnet/threadpool.zip" target="_blank"&gt;&lt;font color="#0066dd"&gt;http://www.bearcanyon.com/dotnet/threadpool.zip&lt;/font&gt;&lt;/a&gt;. This custom thread pool also supports propagation of call context and HttpContext, which means that you can access HttpContext.Current in the asynchronous method, unlike the previous example. The class implementing the thread pool is called DevelopMentor.ThreadPool, and its constructor takes an initial thread count, a maximum thread count, and a string to give the pool a name. To issue asynchronous requests with this pool, call PostRequest and pass in a reference to a WorkRequestDelegate.&lt;/div&gt;&#xD;
&lt;div &gt;To rewrite the asynchronous handler to use this custom thread pool there will be two major changes that just spawned new threads. First, add a static member of type DevelopMentor.ThreadPool to the handler class and a static constructor to initialize the thread pool once per AppDomain. Then change the implementation of BeginProcessRequest to call PostRequest on the thread pool with a new instance of WorkRequestDelegate (see &lt;strong&gt;Figure 8&lt;/strong&gt;). If you run the same stress test performed earlier with the slow.aspx page, this time using the new AsyncPool.ashx handler instead of AsyncThread.aspx, you get the following results. The average response time for fast.aspx is .055 seconds and 12.24 seconds for AsyncThread.ashx with the total number of serviced requests at 1042.&lt;/div&gt;&lt;span&gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;!-- ApplyClick with current id --&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; vertical-align: middle; border-left-width: 0px"  src="http://i.msdn.microsoft.com/Global/Images/clear.gif"  alt="" /&gt; &amp;nbsp;Figure&amp;nbsp;8&amp;nbsp;Calling PostRequest &lt;/div&gt;&#xD;
&lt;div style="display: block" &gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl35_ctl00_ctl00" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl35_ctl00_ctl00_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl35_ctl00_ctl00_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl35_ctl00_ctl00_code"  space="preserve"&gt;&amp;lt;!-- File: AsyncPool.ashx --&amp;gt;&#xD;
&amp;lt;%@ WebHandler Language="C#" &#xD;
     %&amp;gt;&#xD;
&#xD;
namespace EssentialAspDotNet.HttpPipeline&#xD;
{&#xD;
  // AsyncRequestState and AsyncRequest remain the same &#xD;
  // as in the previous example&#xD;
  &#xD;
  public class AsyncHandler : IHttpAsyncHandler&#xD;
  { &#xD;
    static DevelopMentor.ThreadPool _threadPool;&#xD;
&#xD;
    static AsyncHandler()&#xD;
    {&#xD;
      _threadPool = &#xD;
        new DevelopMentor.ThreadPool(2, 25, "AsyncPool");&#xD;
      _threadPool.PropogateCallContext = true;&#xD;
      _threadPool.PropogateThreadPrincipal = true;&#xD;
      _threadPool.PropogateHttpContext = true;&#xD;
      _threadPool.Start();&#xD;
    }&#xD;
&#xD;
    public void ProcessRequest(HttpContext ctx)&#xD;
    {&#xD;
     // not used&#xD;
    }&#xD;
&#xD;
    public bool IsReusable&#xD;
    {&#xD;
      get { return false;}&#xD;
    }&#xD;
&#xD;
    public IAsyncResult BeginProcessRequest(HttpContext ctx, &#xD;
                     AsyncCallback cb, object obj)&#xD;
    {&#xD;
      AsyncRequestState reqState = &#xD;
                     new AsyncRequestState(ctx, cb, obj);&#xD;
      _threadPool.PostRequest(&#xD;
                     new DevelopMentor.WorkRequestDelegate(ProcessRequest),&#xD;
                     reqState);&#xD;
&#xD;
      return reqState;&#xD;
    }&#xD;
&#xD;
    public void EndProcessRequest(IAsyncResult ar)&#xD;
    {&#xD;
    }&#xD;
&#xD;
    void ProcessRequest(object state, DateTime requestTime)&#xD;
    {&#xD;
      AsyncRequestState reqState = state as AsyncRequestState;&#xD;
&#xD;
      // Take some time to do it&#xD;
      Thread.Sleep(2000);&#xD;
      &#xD;
      reqState._ctx.Response.Output.Write(&#xD;
                   "AsyncThreadPool, {0}",&#xD;
                    AppDomain.GetCurrentThreadId);&#xD;
&#xD;
      // tell asp.net you are finished processing this request&#xD;
      reqState.CompleteRequest();&#xD;
    }&#xD;
&#xD;
  }&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&#xD;
&lt;div &gt;Note that the average response time for requests made to fast.aspx is still minimal, and there is no longer the danger of creating an unbounded number of threads. There is some additional management involved with maintaining a second thread pool, which results in the extended request times for the slow handler.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S8" &gt;Asynchronous Pages&lt;/div&gt;&#xD;
&lt;div &gt;So far, all of the examples of asynchronous request handling have involved building custom handlers (in this case, using .ashx files). There will be many cases where you can identify normal pages (.aspx) in your ASP.NET applications that are also good candidates for asynchronous execution because they perform non-CPU-bound tasks that take significant amounts of time. Such pages are also potential bottlenecks for the ASP.NET thread pool. The Page class itself implements the IHttpHandler interface, and thus services requests synchronously. To change a given .aspx page to service requests asynchronously, it is necessary to implement IHttpAsyncHandler in the Page-derived class and then use the techniques described in this article to invoke the ProcessRequest method of the Page class on an alternate thread.&lt;/div&gt;&#xD;
&lt;div &gt;One convenient way to make any page asynchronous is to create an alternate base class from which the primary page can derive and then specify this alternate base class as the base class from which the page should derive using the Inherits attribute of the @Page directive. The AsyncPage class definition shown in &lt;strong&gt;Figure 9&lt;/strong&gt; defines such a base class. Note that this implementation uses the custom thread pool shown earlier to service requests to the page asynchronously. This implementation of BeginProcessRequest invokes the PostRequest method of the thread pool with a new WorkRequestDelegate initialized with a reference to my overload of ProcessRequest. In the overload, I invoke the base class scope of ProcessRequest (with the original signature as defined in the IHttpHandler interface), which performs the standard request processing of a page, only this time it will be performed on the thread pool thread instead of the primary request thread (see &lt;strong&gt;Figure 9&lt;/strong&gt;).&lt;/div&gt;&lt;span&gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;!-- ApplyClick with current id --&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; vertical-align: middle; border-left-width: 0px"  src="http://i.msdn.microsoft.com/Global/Images/clear.gif"  alt="" /&gt; &amp;nbsp;Figure&amp;nbsp;9&amp;nbsp;AsyncPage &lt;/div&gt;&#xD;
&lt;div style="display: block" &gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl36_ctl00_ctl00" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl36_ctl00_ctl00_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl36_ctl00_ctl00_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl36_ctl00_ctl00_code"  space="preserve"&gt;namespace EssentialAspDotNet.HttpPipeline&#xD;
{&#xD;
 public class AsyncPage : Page, IHttpAsyncHandler&#xD;
  { &#xD;
    static protected DevelopMentor.ThreadPool _threadPool;&#xD;
&#xD;
    static AsyncPage()&#xD;
    {&#xD;
      _threadPool = &#xD;
       new DevelopMentor.ThreadPool(2, 25, "AsyncPool");&#xD;
      _threadPool.PropogateCallContext = true;&#xD;
      _threadPool.PropogateThreadPrincipal = true;&#xD;
      _threadPool.PropogateHttpContext = true;&#xD;
      _threadPool.Start();&#xD;
    }&#xD;
&#xD;
    public new void ProcessRequest(HttpContext ctx)&#xD;
    {&#xD;
      // not used&#xD;
    }&#xD;
&#xD;
    public new bool IsReusable&#xD;
    {&#xD;
      get { return false;}&#xD;
    }&#xD;
&#xD;
    public IAsyncResult BeginProcessRequest(HttpContext ctx, &#xD;
                                            AsyncCallback cb, object obj)&#xD;
    {&#xD;
      AsyncRequestState reqState = &#xD;
             new AsyncRequestState(ctx, cb, obj);&#xD;
      _threadPool.PostRequest(&#xD;
             new DevelopMentor.WorkRequestDelegate(ProcessRequest),&#xD;
             reqState);&#xD;
&#xD;
      return reqState;&#xD;
    }&#xD;
&#xD;
    public void EndProcessRequest(IAsyncResult ar)&#xD;
    {&#xD;
    }&#xD;
&#xD;
    void ProcessRequest(object state, DateTime requestTime)&#xD;
    {&#xD;
      AsyncRequestState reqState = state as AsyncRequestState;&#xD;
&#xD;
      // Synchronously call base class Page.ProcessRequest&#xD;
      // as you are now on a thread pool thread. &#xD;
      base.ProcessRequest(reqState._ctx);&#xD;
&#xD;
      // Once complete, call CompleteRequest to finish&#xD;
      reqState.CompleteRequest();&#xD;
    }&#xD;
  }&#xD;
}&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&#xD;
&lt;div &gt;As an example of using this new asynchronous page base class, consider the following ASPX page that inherits from the AsyncPage class. This base class could be applied to any ASPX page in a similar fashion to turn it into an asynchronously executed page: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl23" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;&#xD;
&lt;div id="ctl00_MTContentSelector1_mainContentContainer_ctl23_" &gt;&#xD;
&lt;div &gt;&#xD;
&lt;div &gt;&lt;/div&gt;&#xD;
&lt;div &gt;&lt;a  title="复制代码" href="http://www.cnblogs.com/wubiyu/admin/javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl23_code');" target="_blank"&gt;&#xD;
&lt;div style="border-right-width: 0px; width: auto; border-top-width: 0px; border-bottom-width: 0px; height: 9px; border-left-width: 0px"  align="center"&gt;&lt;/div&gt;复制代码 &lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&lt;div style="background-color: #ddd" dir="ltr"&gt;&lt;pre id="ctl00_MTContentSelector1_mainContentContainer_ctl23_code"  space="preserve"&gt;&amp;lt;!-- AsyncPage.aspx --&amp;gt;&#xD;
&amp;lt;%@ Page Language="C#" &#xD;
    Inherits="EssentialAspDotNet.HttpPipeline.AsyncPage" %&amp;gt;&#xD;
&amp;lt;%@ import Namespace="System.Reflection" %&amp;gt;&#xD;
&amp;lt;%@ import Namespace="System.Threading" %&amp;gt;&#xD;
&#xD;
&amp;lt;script runat="server"&amp;gt;&#xD;
protected void Page_Load(object src, EventArgs e)&#xD;
{&#xD;
   System.Threading.Thread.Sleep(2000);&#xD;
   Response.Output.Write("AsyncPage, {0}",&#xD;
                         AppDomain.GetCurrentThreadId);&#xD;
}&#xD;
&amp;lt;/script&amp;gt;&#xD;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&#xD;
&lt;div &gt;The results of performing the stress test with fast.aspx and the asynchronous page, AsyncPage.aspx, are as follows with results matching those of the asynchronous custom handler using a custom thread pool. The average response time for fast.aspx is .054 seconds and 11.92 seconds for AsyncPage.aspx, with the total number of serviced requests at 965.&lt;/div&gt;&lt;br /&gt;&#xD;
&lt;div id="S9" &gt;Conclusion&lt;/div&gt;&#xD;
&lt;div &gt;Building asynchronous handlers instead of synchronous ones actually adds additional overhead to request processing, so you should take the time to determine if the asynchronous capability of these types of handlers is really what you need. The purpose of an asynchronous handler is to free up an ASP.NET thread pool thread to service additional requests while the handler is processing the original request. This only makes sense if the work of servicing the request requires a significant amount of non-CPU-bound time to complete. For example, if the completion of a request depends on the completion of a number of remote procedure calls, or perhaps Web Service invocations, that would be a candidate to implement an asynchronous handler. Building asynchronous handlers to service CPU-intensive requests only adds threads to compete with the ASP.NET thread pool threads and may actually slow down the overall processing time for the request.&lt;/div&gt; &lt;img src="http://www.cnblogs.com/wubiyu/aggbug/1719689.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/wubiyu/archive/2010/04/25/1719689.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2010/01/29/1659214.html</id><title type="text">[转]COM线程模型-套间</title><summary type="text">首先，只要遵守COM规范，不用COM库也能编写COM程序，那相当于自己实现用到的COM库函数。本篇COM如果单独出现，指COM库。</summary><published>2010-01-29T06:17:00Z</published><updated>2010-01-29T06:17:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2010/01/29/1659214.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2010/01/29/1659214.html"/></entry><entry><id>http://www.cnblogs.com/wubiyu/archive/2009/12/16/1625274.html</id><title type="text">[转]VC使用CRT调试功能来检测内存泄漏</title><summary type="text">C/C++ 编程语言的最强大功能之一便是其动态分配和释放内存，但是中国有句古话：“最大的长处也可能成为最大的弱点”，那么 C/C++ 应用程序正好印证了这句话。在 C/C++ 应用程序开发过程中，动态分配的内存处理不当是最常见的问题。其中，最难捉摸也最难检测的错误之一就是内存泄漏，即未能正确释放以前分配的内存的错误。偶尔发生的少量内存泄漏可能不会引起我们的注意，但泄漏大量内存的程序或泄漏日益增多的程序可能会表现出各种 各样的征兆：从性能不良（并且逐渐降低）到内存完全耗尽。更糟的是，泄漏的程序可能会用掉太多内存，导致另外一个程序垮掉，而使用户无从查找问题的真正根源。此外，即使无害的内存泄漏也可能殃及池鱼。</summary><published>2009-12-16T01:23:00Z</published><updated>2009-12-16T01:23:00Z</updated><author><name>吴碧宇</name><uri>http://www.cnblogs.com/wubiyu/</uri></author><link rel="alternate" href="http://www.cnblogs.com/wubiyu/archive/2009/12/16/1625274.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/wubiyu/archive/2009/12/16/1625274.html"/></entry></feed>
