﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-人生就是一场圣战-GODWAR</title><link>http://www.cnblogs.com/godwar/</link><description>最大的敌人就是自己
No incapable except unthinkable. God helps those who help themselves</description><language>zh-cn</language><lastBuildDate>Fri, 05 Sep 2008 17:59:30 GMT</lastBuildDate><pubDate>Fri, 05 Sep 2008 17:59:30 GMT</pubDate><ttl>60</ttl><item><title>【原創】DevExpress.XtraCharts中BeginUpdate()的嘗試</title><link>http://www.cnblogs.com/godwar/archive/2008/09/04/1284284.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Thu, 04 Sep 2008 10:14:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/09/04/1284284.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1284284.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/09/04/1284284.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1284284.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1284284.html</trackback:ping><description><![CDATA[<P>最經在使用DevExpress.XtraCharts中chartControl1的控件的時候，發現chartControl1.Series[i].Points.Add(sp);</P>
<P>的速度相當慢，而且一直處於停滯狀態；通過原理的分析，可以肯定的是chartControl1.Series[i].Points.Add(sp);的循環造成chartControl1一直在生成，并不是等待所有都Points.Add進去了才生成Chart；<BR>出於對開發者和其他控件的經驗，肯定存在一個控制項用來管理chartControl1.DataSource的進程；<BR><BR>參照 <STRONG>DXperience 7.3.4 released on 3 Dec 2007 and What'a New</STRONG> <BR><A href="http://www.devexpress.com/issue=B90406" target=_blank><SPAN>B90406</SPAN></A><SPAN> - Grid doesn't display rows when a new DataSource is assigned within a BeginUpdate - EndUpdate block<BR><BR>進行試驗：<BR></P>
<DIV class=cnblogs_code><IMG id=Code_Closed_Image_181005 onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_181005').style.display='none'; document.getElementById('Code_Open_Image_181005').style.display='inline'; document.getElementById('Code_Open_Text_181005').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><IMG id=Code_Open_Image_181005 style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_181005').style.display='none'; getElementById('Code_Closed_Image_181005').style.display='inline'; getElementById('Code_Closed_Text_181005').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><SPAN class=cnblogs_code_Collapse id=Code_Closed_Text_181005>Code</SPAN><SPAN id=Code_Open_Text_181005 style="DISPLAY: none"><BR><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><SPAN style="COLOR: #000000">DataTable&nbsp;dtb&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BLL_kkk()).GetListSumForChartsByLines(strSQL).Tables[</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">];<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">6</SPAN><SPAN style="COLOR: #000000">;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chartControl1.Series[i].Points.Clear();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT color=#ff0000>chartControl1.Series[i].Points.BeginUpdate();</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">foreach</SPAN><SPAN style="COLOR: #000000">&nbsp;(DataRow&nbsp;dr&nbsp;</SPAN><SPAN style="COLOR: #0000ff">in</SPAN><SPAN style="COLOR: #000000">&nbsp;dtb.Rows)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">6</SPAN><SPAN style="COLOR: #000000">;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">((DevExpress.XtraCharts.BarSeriesView)chartControl1.Series[i].View).BarWidth&nbsp;=&nbsp;1;</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DevExpress.XtraCharts.SeriesPoint&nbsp;sp&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DevExpress.XtraCharts.SeriesPoint();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sp.Argument&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;dr[</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">].ToString().Trim();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Double[]&nbsp;bi&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">double</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #800080">1</SPAN><SPAN style="COLOR: #000000">];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bi[</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Double.Parse(dr[i&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">1</SPAN><SPAN style="COLOR: #000000">].ToString().Trim());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sp.Values&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;bi;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chartControl1.Series[i].Points.Add(sp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">6</SPAN><SPAN style="COLOR: #000000">;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT color=#ff0000>chartControl1.Series[i].Points.EndUpdate();</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR><BR>速度完全的提升了，效果DataSource ；這只是嘗試所得，任何錯誤請批評指正；<BR>其他控件應該有類似的方法；</SPAN></SPAN></DIV></SPAN><img src ="http://www.cnblogs.com/godwar/aggbug/1284284.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42116/" target="_blank">[新闻]消息称MySQL创始人已向Sun提交辞呈</a>]]></description></item><item><title>【原創】SQL語句對DataGridView的Columns排序產生的影響</title><link>http://www.cnblogs.com/godwar/archive/2008/09/01/1281470.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Mon, 01 Sep 2008 11:29:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/09/01/1281470.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1281470.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/09/01/1281470.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1281470.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1281470.html</trackback:ping><description><![CDATA[今天在做一個簡單的DataGridView新增、修改、刪除功能時，發現在我增加一個ID欄位后所有的ColumnIndex出現位移，都增加了1，首先說明DataGridView的Columns我已經都綁定了并排序；<BR>問題很明顯是增加了一個欄位出現的問題，我就開始排查：<BR><BR>1、檢查ColumnUI設置，沒有發現問題<BR><IMG height=311 alt=IDRowid.png src="http://www.cnblogs.com/images/cnblogs_com/godwar/ArticleIMG/IDRowid.png" width=511 border=0><BR><BR>2、檢查 fr_Main.Designer.cs文件，也沒有發現問題<BR>this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column2,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column3,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column4,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column5,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column6,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column7,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column8,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Column9});<BR><BR><BR>只是發現因為Column9我沒有設置ColumnHeader，少了一個，增加上去還是沒有效果；<BR><BR>3、在我回頭檢查SQL語法時，發現了我增加的欄位ID，放置在select後面，難不成是這個影響了dataGridView的Columns排序<BR>原語句：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strSQL = "select ID,trim(mr01) as mr01,trim(mr02) as mr02,trim(mr03) as mr03,mr04,mr05,trim(mr06) as mr06,mr07,mr08 ";<BR><BR>修改后：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strSQL = "select trim(mr01) as mr01,trim(mr02) as mr02,trim(mr03) as mr03,mr04,mr05,trim(mr06) as mr06,mr07,mr08,ID ";<BR><BR>此時一切正常；不知道大家有沒有遇到這么簡單的問題，感覺沒有面向dataGridView對象保持一致；<img src ="http://www.cnblogs.com/godwar/aggbug/1281470.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42115/" target="_blank">[新闻]谷歌Chrome浏览器即将更换LOGO颜色？</a>]]></description></item><item><title>.Net(c#)通用驗證版本新舊的方法</title><link>http://www.cnblogs.com/godwar/archive/2008/08/28/1278754.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Thu, 28 Aug 2008 08:12:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/28/1278754.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1278754.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/28/1278754.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1278754.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1278754.html</trackback:ping><description><![CDATA[<P>版本號碼常識：<BR><BR>// 組件的版本資訊是由下列四項值構成:<BR>//<BR><FONT color=#ff0000>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 主要版本（第一碼）<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 次要版本（第二碼）</FONT><BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 組建編號（第三碼）<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 修訂編號（第四碼）<BR>//<BR>[assembly: AssemblyVersion("<FONT color=#ff0000><STRONG>1.1</STRONG></FONT>.0.2")]<BR>[assembly: AssemblyFileVersion("<FONT color=#ff0000><STRONG>1.1</STRONG></FONT>.0.2")]<BR></P>
<DIV class=cnblogs_code><IMG id=Code_Closed_Image_155903 onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_155903').style.display='none'; document.getElementById('Code_Open_Image_155903').style.display='inline'; document.getElementById('Code_Open_Text_155903').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><IMG id=Code_Open_Image_155903 style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_155903').style.display='none'; getElementById('Code_Closed_Image_155903').style.display='inline'; getElementById('Code_Closed_Text_155903').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><SPAN class=cnblogs_code_Collapse id=Code_Closed_Text_155903>驗證版本</SPAN><SPAN id=Code_Open_Text_155903 style="DISPLAY: none"><BR><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">bool</SPAN><SPAN style="COLOR: #000000">&nbsp;CheckCurrentVersion(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;CurrentVersion,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;ServerVersion)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i;<BR>&nbsp;&nbsp;&nbsp;&nbsp;Exception&nbsp;ex;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]&nbsp;ListCurrentVersion&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;CurrentVersion.Split(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">[]&nbsp;{&nbsp;</SPAN><SPAN style="COLOR: #800000">'</SPAN><SPAN style="COLOR: #800000">.</SPAN><SPAN style="COLOR: #800000">'</SPAN><SPAN style="COLOR: #000000">&nbsp;},&nbsp;StringSplitOptions.RemoveEmptyEntries);//<FONT size=2>返回字符串數組</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]&nbsp;ListServerVersion&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ServerVersion.Split(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">[]&nbsp;{&nbsp;</SPAN><SPAN style="COLOR: #800000">'</SPAN><SPAN style="COLOR: #800000">.</SPAN><SPAN style="COLOR: #800000">'</SPAN><SPAN style="COLOR: #000000">&nbsp;},&nbsp;StringSplitOptions.RemoveEmptyEntries);//同上<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">bool</SPAN><SPAN style="COLOR: #000000">&nbsp;IsUpdate&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;iCurrent&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;iServer&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(ListCurrentVersion.Length&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;ListServerVersion.Length) <FONT color=#ff0000>//Godwar:相同版本長度的判斷</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;ListCurrentVersion.Length;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iServer&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">.Parse(ListServerVersion[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(Exception&nbsp;exception1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;exception1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iCurrent&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">.Parse(ListCurrentVersion[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(Exception&nbsp;exception2)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;exception2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(iServer&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;iCurrent)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;IsUpdate;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(iServer&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;iCurrent)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;IsUpdate;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">bool</SPAN><SPAN style="COLOR: #000000">&nbsp;IsListCurrentVersionMax&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(ListCurrentVersion.Length&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;ListServerVersion.Length) <FONT color=#ff0000>//Godwar:當版本長度不一致，按照從左向右依主次順序判斷<BR></FONT>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IsListCurrentVersionMax&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;iMin&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(ListCurrentVersion.Length&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;ListServerVersion.Length)&nbsp;</SPAN><SPAN style="COLOR: #000000">?</SPAN><SPAN style="COLOR: #000000">&nbsp;ListCurrentVersion.Length&nbsp;:&nbsp;ListServerVersion.Length;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;iMin;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iServer&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">.Parse(ListServerVersion[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(Exception&nbsp;exception3)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;exception3;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iCurrent&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">.Parse(ListCurrentVersion[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(Exception&nbsp;exception4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;exception4;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(iServer&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;iCurrent)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;IsUpdate;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(iServer&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;iCurrent)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;IsUpdate; <FONT color=#ff0000>// 返回是否需要升級，即本地版本是否小於服務器最新版本</FONT><BR>}<BR><BR>&nbsp;<BR><BR>&nbsp;<BR></SPAN></SPAN></DIV><img src ="http://www.cnblogs.com/godwar/aggbug/1278754.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42101/" target="_blank">[新闻]淘宝网合并阿里妈妈 专家称阿里巴巴或有新战略</a>]]></description></item><item><title>【原創】關於C#程序調用Process.Start并获得启动参数的問題</title><link>http://www.cnblogs.com/godwar/archive/2008/08/28/1278474.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Thu, 28 Aug 2008 03:32:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/28/1278474.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1278474.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/28/1278474.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1278474.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1278474.html</trackback:ping><description><![CDATA[參考文章：<BR><A href="http://msdn.microsoft.com/zh-cn/h6ak8zt5.aspx">http://msdn.microsoft.com/zh-cn/h6ak8zt5.aspx</A><BR><A style="COLOR: #0000ff; TEXT-DECORATION: underline" href="http://www.microsoft.com/china/MSDN/library/netFramework/netframework/SystemDiag.mspx">http://www.microsoft.com/china/MSDN/library/netFramework/netframework/SystemDiag.mspx</A><BR><BR>
<DIV class=majorTitle>一、.NET Framework 类库&nbsp; Process<SPAN class=cs>.</SPAN><SPAN class=vb>.</SPAN><SPAN class=cpp>::</SPAN><SPAN class=nu>.</SPAN>Start 方法 <!----></DIV><!--
      Content type: Devdiv1. Transform: orcas2mtps.xslt.
    -->
<DIV id=mainSection>
<DIV id=mainBody>
<DIV class=summary>
<P>启动进程资源并将其与 <A id=ctl00_mainContentContainer_ctl03 onclick="javascript:Track('ctl00_mainContentContainer_ctl00|ctl00_mainContentContainer_ctl03',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.aspx">Process</A> 组件关联。</P></DIV>
<DIV class=MTPS_CollapsibleRegion id=ctl00_mainContentContainer_cpe39207>
<DIV class=CollapseRegionLink id=ctl00_mainContentContainer_cpe39207_h><IMG id=ctl00_mainContentContainer_cpe39207_i style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; VERTICAL-ALIGN: middle; BORDER-RIGHT-WIDTH: 0px" src="http://i.msdn.microsoft.com/Platform/Controls/CollapsibleArea/resources/minus.gif">&nbsp;重载列表 </DIV>
<DIV class=MTPS_CollapsibleSection id=ctl00_mainContentContainer_cpe39207_c style="DISPLAY: block; OVERFLOW: visible; WIDTH: auto; HEIGHT: auto">
<DIV class=MTPS_CollapsibleSection id="" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; DISPLAY: block; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none"><A name=overloadMembersTableToggle><!----></A>
<TABLE class=members id=memberList frame=lhs>
<COLGROUP>
<COL width="10%">
<TBODY>
<TR>
<TH class=iconColumn>&nbsp; </TH>
<TH class=nameColumn>名称</TH>
<TH class=descriptionColumn>说明</TH></TR>
<TR data="public;declared;netcfw;">
<TD><IMG title=公共方法 src="http://i.msdn.microsoft.com/92699yzt.pubmethod(zh-cn,VS.90).gif"> <IMG title=".NET Compact Framework 提供支持" src="http://i.msdn.microsoft.com/92699yzt.CFW(zh-cn,VS.90).gif" data="netcfw"> </TD>
<TD><A id=ctl00_mainContentContainer_ctl20 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl20',this);" href="http://msdn.microsoft.com/zh-cn/e8zac0ca.aspx"><FONT color=#0033cc>Start<SPAN class=cs>()</SPAN><SPAN class=cpp>()</SPAN><SPAN class=nu>()</SPAN></FONT></A> </TD>
<TD>启动（或重用）此 <A id=ctl00_mainContentContainer_ctl22 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl22',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.aspx">Process</A> 组件的 <A id=ctl00_mainContentContainer_ctl23 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl23',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.startinfo.aspx"><FONT color=#0033cc>StartInfo</FONT></A> 属性指定的进程资源，并将其与该组件关联。</TD></TR>
<TR data="public;static;declared;netcfw;">
<TD><IMG title=公共方法 src="http://i.msdn.microsoft.com/92699yzt.pubmethod(zh-cn,VS.90).gif"> <IMG title=静态成员 src="http://i.msdn.microsoft.com/92699yzt.static(zh-cn,VS.90).gif"> <IMG title=".NET Compact Framework 提供支持" src="http://i.msdn.microsoft.com/92699yzt.CFW(zh-cn,VS.90).gif" data="netcfw"> </TD>
<TD><A id=ctl00_mainContentContainer_ctl24 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl24',this);" href="http://msdn.microsoft.com/zh-cn/0w4h05yb.aspx"><FONT color=#0033cc>Start(ProcessStartInfo)</FONT></A> </TD>
<TD>启动由包含进程启动信息（例如，要启动的进程的文件名）的参数指定的进程资源，并将该资源与新的 <A id=ctl00_mainContentContainer_ctl25 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl25',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.aspx">Process</A> 组件关联。</TD></TR>
<TR data="public;static;declared;">
<TD><IMG title=公共方法 src="http://i.msdn.microsoft.com/92699yzt.pubmethod(zh-cn,VS.90).gif"> <IMG title=静态成员 src="http://i.msdn.microsoft.com/92699yzt.static(zh-cn,VS.90).gif"> </TD>
<TD><A id=ctl00_mainContentContainer_ctl26 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl26',this);" href="http://msdn.microsoft.com/zh-cn/53ezey2s.aspx"><FONT color=#0033cc>Start(String)</FONT></A> </TD>
<TD>通过指定文档或应用程序文件的名称来启动进程资源，并将资源与新的 <A id=ctl00_mainContentContainer_ctl27 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl27',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.aspx">Process</A> 组件关联。</TD></TR>
<TR data="public;static;declared;netcfw;">
<TD><STRONG><FONT color=#9acd32><IMG title=公共方法 src="http://i.msdn.microsoft.com/92699yzt.pubmethod(zh-cn,VS.90).gif"> <IMG title=静态成员 src="http://i.msdn.microsoft.com/92699yzt.static(zh-cn,VS.90).gif"> <IMG title=".NET Compact Framework 提供支持" src="http://i.msdn.microsoft.com/92699yzt.CFW(zh-cn,VS.90).gif" data="netcfw"> </FONT></STRONG></TD>
<TD><A id=ctl00_mainContentContainer_ctl28 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl28',this);" href="http://msdn.microsoft.com/zh-cn/h6ak8zt5.aspx"><STRONG><FONT color=#9acd32>Start(String, String)</FONT></STRONG></A><STRONG><FONT color=#9acd32> </FONT></STRONG></TD>
<TD><STRONG><FONT color=#9acd32>通过指定应用程序的名称和一组命令行参数来启动一个进程资源，并将该资源与新的 </FONT></STRONG><A id=ctl00_mainContentContainer_ctl29 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl29',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.aspx"><STRONG><FONT color=#9acd32>Process</FONT></STRONG></A><STRONG><FONT color=#9acd32> 组件相关联。</FONT></STRONG></TD></TR>
<TR data="public;static;declared;">
<TD><IMG title=公共方法 src="http://i.msdn.microsoft.com/92699yzt.pubmethod(zh-cn,VS.90).gif"> <IMG title=静态成员 src="http://i.msdn.microsoft.com/92699yzt.static(zh-cn,VS.90).gif"> </TD>
<TD><A id=ctl00_mainContentContainer_ctl30 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl30',this);" href="http://msdn.microsoft.com/zh-cn/sxf2saat.aspx"><FONT color=#0033cc>Start(String, String, SecureString, String)</FONT></A> </TD>
<TD>通过指定应用程序的名称、用户名、密码和域来启动一个进程资源，并将该资源与新的 <A id=ctl00_mainContentContainer_ctl31 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl31',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.aspx">Process</A> 组件关联起来。</TD></TR>
<TR data="public;static;declared;">
<TD><IMG title=公共方法 src="http://i.msdn.microsoft.com/92699yzt.pubmethod(zh-cn,VS.90).gif"> <IMG title=静态成员 src="http://i.msdn.microsoft.com/92699yzt.static(zh-cn,VS.90).gif"> </TD>
<TD><A id=ctl00_mainContentContainer_ctl32 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl32',this);" href="http://msdn.microsoft.com/zh-cn/ed04yy3t.aspx"><FONT color=#0033cc>Start(String, String, String, SecureString, String)</FONT></A> </TD>
<TD>通过指定应用程序的名称、一组命令行参数、用户名、密码和域来启动一个进程资源，并将该资源与新的 <A id=ctl00_mainContentContainer_ctl33 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl33',this);" href="http://msdn.microsoft.com/zh-cn/system.diagnostics.process.aspx">Process</A> 组件关联起来。</TD></TR></TBODY></TABLE></DIV></DIV></DIV></DIV></DIV><BR><BR>在使用Process.Start中可以使用Process.<A id=ctl00_mainContentContainer_ctl28 onclick="javascript:Track('ctl00_mainContentContainer_cpe39207_c|ctl00_mainContentContainer_ctl28',this);" href="http://msdn.microsoft.com/zh-cn/h6ak8zt5.aspx"><FONT color=#9acd32><STRONG>Start(String, String)</STRONG></FONT></A><FONT color=#9acd32> </FONT><FONT style="BACKGROUND-COLOR: #ffffff" color=#000000>的方式，也可以使用下面的方式：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Process myProcess = <SPAN style="COLOR: blue">new</SPAN> Process();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: green">// Get the path that stores user documents.</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">string</SPAN> myDocumentsPath = <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Environment.GetFolderPath(Environment.SpecialFolder.Personal);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myProcess.StartInfo.FileName = myDocumentsPath + <SPAN style="COLOR: maroon"><SPAN style="COLOR: maroon">"\\MyFile.doc"</SPAN></SPAN>; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myProcess.StartInfo.Verb = <SPAN style="COLOR: maroon"><SPAN style="COLOR: maroon">"Print"</SPAN></SPAN>;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myProcess.StartInfo.CreateNoWindow = <SPAN style="COLOR: blue">true</SPAN>;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myProcess.Start();<BR><BR>二、获得启动参数的方法<BR><BR>1、</FONT>傳值<BR>專案根目錄下 Program.cs<BR><BR>
<DIV class=cnblogs_code><IMG id=Code_Closed_Image_112956 onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_112956').style.display='none'; document.getElementById('Code_Open_Image_112956').style.display='inline'; document.getElementById('Code_Open_Text_112956').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><IMG id=Code_Open_Image_112956 style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_112956').style.display='none'; getElementById('Code_Closed_Image_112956').style.display='inline'; getElementById('Code_Closed_Text_112956').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><SPAN class=cnblogs_code_Collapse id=Code_Closed_Text_112956>Code</SPAN><SPAN id=Code_Open_Text_112956 style="DISPLAY: none"><BR><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><SPAN style="COLOR: #808080">///</SPAN><SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #808080">&lt;summary&gt;</SPAN><SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #808080">///</SPAN><SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;应用程序的主入口点。&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #808080">///</SPAN><SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #808080">&lt;/summary&gt;</SPAN><SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #808080"><BR></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;[STAThread]&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;Main(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]&nbsp;&nbsp;&nbsp;args)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;Application.Run(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;Form1(args))&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">------------------------</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;Form1(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">[]&nbsp;&nbsp;&nbsp;args)&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用args&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<BR><BR>2、全局獲取<BR><BR>
<DIV class=cnblogs_code><IMG id=Code_Closed_Image_113030 onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_113030').style.display='none'; document.getElementById('Code_Open_Image_113030').style.display='inline'; document.getElementById('Code_Open_Text_113030').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><IMG id=Code_Open_Image_113030 style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_113030').style.display='none'; getElementById('Code_Closed_Image_113030').style.display='inline'; getElementById('Code_Closed_Text_113030').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><SPAN class=cnblogs_code_Collapse id=Code_Closed_Text_113030>Code</SPAN><SPAN id=Code_Open_Text_113030 style="DISPLAY: none"><BR><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;[]&nbsp;&nbsp;&nbsp;strArgs</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">System.Environment.GetCommandLineArgs();</SPAN></SPAN></DIV><BR>需要注意的是，strArgs[0]就是當前啟動程序的路徑，而不是來源調用的程序路徑；<BR></SPAN></SPAN></DIV><img src ="http://www.cnblogs.com/godwar/aggbug/1278474.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42101/" target="_blank">[新闻]淘宝网合并阿里妈妈 专家称阿里巴巴或有新战略</a>]]></description></item><item><title>[ZT]一个优秀软件开发人员的必修课：高内聚低耦合</title><link>http://www.cnblogs.com/godwar/archive/2008/08/27/1277931.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Wed, 27 Aug 2008 09:57:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/27/1277931.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1277931.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/27/1277931.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1277931.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1277931.html</trackback:ping><description><![CDATA[<DIV class=blogstory>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">一个优秀软件开发人员的必修课：</SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">高内聚</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><?XML:NAMESPACE PREFIX = O /><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体">高内聚</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: black"><FONT face="Times New Roman"> Java </FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体">软件工程</SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: black"><FONT face="Times New Roman"> </FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体">软件模式</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: black"><FONT face="Times New Roman"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><O:P></O:P></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体">一个重要的模式：高内聚。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: black"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><FONT face="Times New Roman">2.<SPAN>&nbsp; </SPAN></FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">高内聚（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><FONT face="Times New Roman">High Cohesion</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">高 内聚是另一个普遍用来评判软件设计质量的标准。内聚，更为专业的说法叫功能内聚，是对软件系统中元素职责相关性和集中度的度量。如果元素具有高度相关的职 责，除了这些职责内的任务，没有其它过多的工作，那么该元素就具有高内聚性，反之则为低内聚性。高内聚要求软件系统中的各个元素具有较高的协作性，因为在 我们在完成软件需求中的一个功能，可能需要做各种事情，但是具有高内聚性的一个元素，只完成它职责内的事情，而把那些不在它职责内的事情拿去请求别人来完 成。这就好像，如果我是一个项目经理，我的职责是监控和协调我的项目各个阶段的工作。当我的项目进入需求分析阶段，我会请求需求分析员来完成；当我的项目 进入开发阶段，我会请求软件开发人员来完成；当我的项目需要测试的时候，我会请求测试人员。。。。。。如果我参与了开发，我就不是一个高内聚的元素，因为 开发不是我的职责。我们的项目为什么要高内聚呢？我觉得可以从可读性、复用性、可维护性和易变更性四个方面来理解。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><FONT face="Times New Roman">1</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">．可读性</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">一 个人写文章、讲事情，条理清晰才能易于理解，这同样发生在读写软件代码上。如果一堆代码写得一团乱麻，东一个跳转西一个调用，读它的人会感觉非常头疼。这 种事情也许一直在写程序的你我都曾经有过经历。如果一段程序条理非常清晰，每个类通过名称或说明都能清楚明白它的意义，类的每个属性、函数也都是易于理解 的它所应当完成的任务和行为，这段程序的可读性必然提高。在软件产业越来越密集，软件产业中开发人员协作越来越紧密、分工越来越细的今天，软件可读性的要 求相信也越来越为人们所重视。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">．复用性</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">在软件开发中，最低等级的复用是代码拷贝，然后是函数的复用、对象的复用、组件的复用。软件开发中最懒的人是最聪明的人，他们总是想到复用。在代码编写的时候突然发现某个功能是曾经实现过的功能，直接把它拷贝过来就</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">ok</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">了。 如果这段代码在同一个对象中，那么就提出来写一个函数到处调用就行了。如果不是在同一个对象中呢，就将其抽象成一个对象到处调用吧。如果不在一个项目中 呢，那就做成组件给各个项目引用吧。代码复用也使我们的代码在复用的过程中不断精化、不断健壮、提高代码质量。代码的复用的确给我们的开发带来了不少便 利，但是一段代码能否在各个需要的地方都能复用呢？这给我们的软件开发质量提出了新的要求：好的代码可以复用，不好的则不行。软件中的一个对象如果能保证 能完成自己职能范围内的各项任务，同时又不去理会与自己职能无关的其它任务，那么它就能够保证功能的相对独立性，也就可以脱离自己所处的环境而复用到其它 环境中，这是一个具有内聚性的对象。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><FONT face="Times New Roman">3</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">．可维护性和易变更性</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">在前面《如何在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">struts+spring+hibernate</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的 框架下构建低耦合高内聚的软件》中我提到，我们现在的软件是在不断变更的，这种变更不仅来自于我们的客户，更来自于我们的市场。如果我们的软件通过变更能 及时适应我们的市场需求，我们就可以在市场竞争中获胜。如何能及时变更以适应我们的市场呢，就是通过调整软件的结构，使我们每次的变更付出的代价最小，耗 费的人力最小，这种变更才最快最经济。高内聚的软件，每个系统、模块、类的任务都高度相关，就使每一次的变更涉及的范围缩小到最小。比如评审表发生了变 更，只会与评审表对象有关，我们不会去更改其它的对象。如果我们能做到这一点，我们的系统当然是可维护性好、易变更性好的系统。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">那 么，我们如何做到高内聚呢？就拿前面我提到的评审项目举例。我现在要为“评审表”对象编写一段填写并保存评审表的代码。评审表对象的职责是更新和查询评审 表的数据，但是在显示一个要填写的评审表的时候，我需要显示该评审计划的名称、该评审计划有哪些评审对象需要评审。现在我如何编写显示一个要填写的评审表 的代码？我在评审表对象的这个相应的函数中编写一段查询评审计划和评审对象的代码吗？假如你这样做了，你的代码就不是高内聚的，因为查询评审计划和评审对 象的数据不是它的职责。正确的方法应当去请求“评审计划”对象和“评审对象”对象来完成这些工作，而“评审表”对象只是获取其结果。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">另 外，如果一个对象要完成一个虽然在自己职责范围内，但过程非常复杂的任务时，也应当将该任务分解成数个功能相对独立的子函数来完成。我曾经看见一个朋友写 的数百行的一个函数，让人读起来非常费劲。同时这样的函数中一些相对独立的代码，本可以复用到其它代码中，也变成了不可能。所以我给大家的建议是，不要写 太长的函数，超过一百行就可以考虑将一些功能分解出去。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">与 “低耦合”一样，高内聚也不是一个绝对，而是一个相对的指标，应当适当而不能过度。正如我们在现实生活中，如果在一个十来人的小公司，每个人的分工可能会 粗一些，所分配的职责会广一些杂一些，因为其总体的任务少；而如果在一个一两百人的大公司，每个人的分工会细一些，所分配的任务会更加专一些，因为总体任 务多，更需要专业化的分工来提高效率。软件开发也是一样，如果“评审计划”对象完成的业务功能少，并且不复杂，它完全可以代理它的子表“评审对象”和“评 审者”的管理。但是“评审计划”对象需要完成的“对评审计划表的管理”这个基本职责包含的业务功能繁多或者复杂，它就应当将“对评审对象表的管理”交给“ 评审对象”对象，将“对评审者表的管理”交给“评审者”对象。同样，高内聚的可维护性好、易变更性好只能是一个相对的指标。如果一个变更的确是大范围的变 更，你永远不可能通过内聚就不进行大范围的变更了。同时内聚也是要付出代价的，所以你也不必要去为了一个不太可能的变更去进行过度设计，应当掌握一个度。 过度的内聚必将增加系统中元素之间的依赖，提高耦合度。所以“高内聚”与“低耦合”是矛盾的，必须权衡利弊，综合地去处理。在李洋等人翻译的《</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">UML</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">和模式应用》中，将内聚和耦合翻译为软件工程中的阴与阳，是中国人对内聚和耦合的最佳解释。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">综上所述，“高内聚”给软件项目带来的优点是：可读性强、易维护和变更、支持低耦合、移植和重用性强。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P><FONT face="Times New Roman">&nbsp;</FONT></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 15pt; COLOR: blue; FONT-FAMILY: 宋体">一个优秀软件开发人员的必修课：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 15pt; COLOR: blue"><FONT face="Times New Roman">GRASP</FONT></SPAN><SPAN style="FONT-SIZE: 15pt; COLOR: blue; FONT-FAMILY: 宋体">（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 15pt; COLOR: blue"><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-SIZE: 15pt; COLOR: blue; FONT-FAMILY: 宋体">）低耦合</SPAN><SPAN lang=EN-US style="FONT-SIZE: 15pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">关键字</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">: </FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">设计模式</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><O:P></O:P></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">我偶然在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">google</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">yahoo</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">这样的搜索引擎搜索</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">GRASP</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">发现，除了国外的网站，国内网站多介绍和讨论</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">GoF</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">而很少介绍</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">GRASP</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，即使这少量的文章也讲解非常粗略。个人认为作为优秀的开发人员，理解</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">GRASP</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">比</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">GoF</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">更重要，故写此文章。前面我在《</SPAN><SPAN style="FONT-SIZE: 12pt"><FONT face="Times New Roman"> </FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">（原创）一个优秀软件开发人员的必修课：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">GRASP</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">软件开发模式浅析》中介绍了使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">GRASP</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的目的，今天允许我调换一下顺序，先从低耦合讲起，因为诸如创建者模式、信息专家模式的根本目的就是降低耦合。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman"> <O:P></O:P></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 18pt; COLOR: blue"><FONT face="Times New Roman">1.<SPAN>&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN><SPAN style="FONT-SIZE: 18pt; COLOR: blue; FONT-FAMILY: 宋体">低耦合（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 18pt; COLOR: blue"><FONT face="Times New Roman">Low Coupling</FONT></SPAN><SPAN style="FONT-SIZE: 18pt; COLOR: blue; FONT-FAMILY: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 18pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">“低耦合”这个词相信大家已经耳熟能详，我们在看</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">spring</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的书籍、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">MVC</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的数据、设计模式的书籍，无处不提到“低耦合、高内聚”，它已经成为软件设计质量的标准之一。那么什么是低耦合？耦合就是对某元素与其它元素之间的连接、感知和依赖的量度。这里所说的元素，即可以是功能、对象（类），也可以指系统、子系统、模块。假如一个元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">去连接元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，或者通过自己的方法可以感知</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，或者当</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">不存在的时候就不能正常工作，那么就说元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">与元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">耦合。耦合带来的问题是，当元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">发生变更或不存在时，都将影响元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的正常工作，影响系统的可维护性和易变更性。同时元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">只能工作于元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">存在的环境中，这也降低了元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的可复用性。正因为耦合的种种弊端，我们在软件设计的时候努力追求“低耦合”。低耦合就是要求在我们的软件系统中，某元素不要过度依赖于其它元素。请注意这里的“过度”二字。系统中低耦合不能过度，比如说我们设计一个类可以不与</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">JDK</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">耦合，这可能吗？除非你不是设计的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">Java</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">程序。再比如我设计了一个类，它不与我的系统中的任何类发生耦合。如果有这样一个类，那么它必然是低内聚（关于内聚的问题我随后讨论）。耦合与内聚常常是一个矛盾的两个方面。最佳的方案就是寻找一个合适的中间点。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">哪些是耦合呢？</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">1</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">．元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">是元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的属性，或者元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">引用了元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的实例（这包括元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">调用的某个方法，其参数中包含元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">）。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">．元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">调用了元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的方法。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">3</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">．元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">直接或间接成为元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的子类。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">4</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">．元素</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">是接口</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的实现。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">幸运的是，目前已经有大量的框架帮助我们降低我们系统的耦合度。比如，使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">struts</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">我们可以应用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">MVC</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">模型，使页面展现与业务逻辑分离，做到了页面展现与业务逻辑的低耦合。当我们的页面展现需要变更时，我们只需要修改我们的页面，而不影响我们的业务逻辑；同样，我们的业务逻辑需要变更的时候，我们只需要修改我们的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">java</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">程序，与我们的页面无关。使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">spring</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">我们运用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">IoC</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">（反向控制），降低了业务逻辑中各个类的相互依赖。假如类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">因为需要功能</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">F</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">而调用类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，在通常的情况下类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">需要引用类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，因而类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">就依赖于类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">了，也就是说当类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">不存在的时候类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">就无法使用了。使用了</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">IoC</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">调用的仅仅是实现了功能</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">F</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的接口的某个类，这个类可能是类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，也可能是另一个类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">C</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，由</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">spring</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的配置文件来决定。这样，类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">就不再依赖于类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">了，耦合度降低，重用性提高了。使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">hibernate</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">则是使我们的业务逻辑与数据持久化分离，也就是与将数据存储到数据库的操作分离。我们在业务逻辑中只需要将数据放到值对象中，然后交给</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">hibernate</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，或者从</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">hibernate</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">那里得到值对象。至于用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">Oracle</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">MySQL</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">还是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">SQL Server</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，如何执行的操作，与我无关。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">但是，作为优秀的开发人员，仅仅依靠框架提供的降低软件耦合的方法是远远不够的。根据我的经验，以下一些问题我们应当引起注意：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 18pt; COLOR: blue"><FONT face="Times New Roman">1</FONT></SPAN><SPAN style="FONT-SIZE: 18pt; COLOR: blue; FONT-FAMILY: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 18pt; COLOR: blue"><SPAN><FONT face="Times New Roman">&nbsp;&nbsp; </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 18pt; COLOR: blue; FONT-FAMILY: 宋体">根据可能的变化设计软件</SPAN><SPAN lang=EN-US style="FONT-SIZE: 18pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">我 们采用职责驱动设计，设计中尽力做到“低耦合、高内聚”的一个非常重要的前提是，我们的软件是在不断变化的。如果没有变化我们当然就不用这么费劲了；但是 如果有变化，我们希望通过以上的设计，使我们在适应或者更改这样的变化的时候，付出更小的代价。这里提供了一个非常重要的信息是，我们努力降低耦合的是那 些可能发生变更的地方，因为降低耦合是有代价的，是以增加资源耗费和代码复杂度为代价的。如果系统中某些元素不太可能变更，或者降低耦合所付出的代价太 大，我们当然就应当选择耦合。有一次我试图将我的表现层不依赖于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">struts</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，但发现这样的尝试代价太大而失去意义了。对于软件可能变更的部分，我们应当努力去降低耦合，这就给我们提出一个要求是，在软件设计的时候可以预判日后的变化。根据以往的经验我认为，一个软件的业务逻辑和采用的技术框架往往是容易变化的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">个方面。客户需求变更是我们软件设计必须考虑的问题。在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">RUP</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的 开发过程中，为什么需要将分析设计的过程分为分析模型和设计模型，愚以为，从分析模型到设计模型的过程实际上是系统从满足直接的客户需求到优化系统结构、 适应可预见的客户需求变更的一个过程。这种客户需求的变更不仅仅指对一个客户需求的变更，更是指我们的软件从适应一个客户需求到适应更多客户需求的过程。 另一个方面，现在技术变更之快，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">EJB</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">hibernate</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">spring</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">ajax</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，一个一个的技术像走马灯一样从我们脑海中滑过，我们真不知道明天我在用什么。在这样的情况下，适应变化就是我们最佳的选择。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><SPAN><FONT face="Times New Roman">&nbsp;&nbsp; </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">合理的职责划分</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">合理的职责划分，让系统中的对象各司其职，不仅是提高内聚的要求，同时也可以有效地降低耦合。比如评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、评审表</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、评审报告</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">都需要通过评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">DAO</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">去查询一些评审计划的数据，如果它们都去直接调用评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">DAO</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">（如图</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">），则评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、评审表</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">、评审报告</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">三个对象都与评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">DAO</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">耦合，评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">DAO</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">一旦变更将与这三个对象都有关。在这个实例中，实际上评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">是信息专家（关于信息专家模式我将在后面讨论），评审表</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">和评审报告</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">如果需要获得评审计划的数据，应当向评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">提出需求，由评审计划</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">BUS</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">提供数据（如图</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">）。经过这样的调整，系统的耦合度就降低了。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt"><?XML:NAMESPACE PREFIX = V /><V:SHAPETYPE id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><V:STROKE joinstyle="miter"></V:STROKE><V:FORMULAS><V:F eqn="if lineDrawn pixelLineWidth 0"></V:F><V:F eqn="sum @0 1 0"></V:F><V:F eqn="sum 0 0 @1"></V:F><V:F eqn="prod @2 1 2"></V:F><V:F eqn="prod @3 21600 pixelWidth"></V:F><V:F eqn="prod @3 21600 pixelHeight"></V:F><V:F eqn="sum @0 0 1"></V:F><V:F eqn="prod @6 1 2"></V:F><V:F eqn="prod @7 21600 pixelWidth"></V:F><V:F eqn="sum @8 21600 0"></V:F><V:F eqn="prod @7 21600 pixelHeight"></V:F><V:F eqn="sum @10 21600 0"></V:F></V:FORMULAS><V:PATH o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></V:PATH><O:LOCK v:ext="edit" aspectratio="t"></O:LOCK></V:SHAPETYPE><V:SHAPE id=_x0000_i1025 style="WIDTH: 511.5pt; HEIGHT: 247.5pt" type="#_x0000_t75"><V:IMAGEDATA src="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_image001.jpg" o:title="aaa1"></V:IMAGEDATA></V:SHAPE><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><FONT face="Times New Roman">3</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><SPAN><FONT face="Times New Roman">&nbsp;&nbsp; </FONT></SPAN></SPAN><SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体">使用接口而不是继承</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue"><O:P></O:P></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">通过对耦合的分析，我们不难发现，继承就是一种耦合。如果子类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">继承了父类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">，不论是直接或间接的继承，子类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">都必将依赖父类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">。子类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">必须使用在存在父类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的环境中，父类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">不存在子类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">就不能使用，这样将影响子类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的可移植性。一旦父类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">发生任何变更，更改或去掉一个函数名，或者改变一个函数的参数，都将导致子类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">不得不变更，甚至重写。假如父类</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的子类数十上百个，甚至贯穿这个项目各个模块，这样的变更是灾难性的。这种情况最典型的例子是我们现在使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">hibernate</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">spring</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">设计</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman">DAO</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">对象的方式，具体的描述参见我写的《如何在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><FONT face="Times New Roman"> struts + spring + hibernate</FONT></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">的框架下构建低耦合高内聚的软件结构》一文。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt"><O:P></O:P></SPAN></P><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体">总之，“低耦合”给软件项目带来的优点是：易于变更、易于重用。</SPAN></DIV><img src ="http://www.cnblogs.com/godwar/aggbug/1277931.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42096/" target="_blank">[新闻]微软研究院发布 AutoCollage - 整理并融合照片</a>]]></description></item><item><title>【原創】文件系統-目錄文件快速複製轉移工具</title><link>http://www.cnblogs.com/godwar/archive/2008/08/27/1277436.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Wed, 27 Aug 2008 03:34:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/27/1277436.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1277436.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/27/1277436.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1277436.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1277436.html</trackback:ping><description><![CDATA[摘要: 最近因為公司圖文服務器空間緊張，需要將備份目錄下的所有文件按照目錄結構全部轉移，但是原地址的目錄結構保持不變，在網上搜索無果的情況下，決定自己動手製作一個；UI畫面：主要用到的命名空間：using System.IO;步驟詳解：1、循環來源目錄的所有目錄及文件，重點取得需要轉移的文件數，以便下一步初始化列舉數；2、循環來源目錄的所有目錄，同時取得目錄數和文件大小，并產生需要轉移的文件列表strin&nbsp;&nbsp;<a href='http://www.cnblogs.com/godwar/archive/2008/08/27/1277436.html'>阅读全文</a><img src ="http://www.cnblogs.com/godwar/aggbug/1277436.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42096/" target="_blank">[新闻]微软研究院发布 AutoCollage - 整理并融合照片</a>]]></description></item><item><title>【原創】字符首字母大寫格式化函數</title><link>http://www.cnblogs.com/godwar/archive/2008/08/26/1276899.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Tue, 26 Aug 2008 09:41:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/26/1276899.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1276899.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/26/1276899.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1276899.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1276899.html</trackback:ping><description><![CDATA[<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private string FormatStringToUpper(string str)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (str.Length &gt; 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str0 = str.Substring(0, 1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str1 = str.Substring(1, str.Length - 1);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return str0.ToUpper() + str1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return str;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><img src ="http://www.cnblogs.com/godwar/aggbug/1276899.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42100/" target="_blank">[新闻]2008年9月5日科技博客精选</a>]]></description></item><item><title>如何將程序的Access数据库嵌入到资源中发布</title><link>http://www.cnblogs.com/godwar/archive/2008/08/26/1276842.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Tue, 26 Aug 2008 09:06:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/26/1276842.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1276842.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/26/1276842.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1276842.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1276842.html</trackback:ping><description><![CDATA[<DIV class=cnblogs_code><IMG id=Code_Closed_Image_170402 onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_170402').style.display='none'; document.getElementById('Code_Open_Image_170402').style.display='inline'; document.getElementById('Code_Open_Text_170402').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" width=11 align=top><IMG id=Code_Open_Image_170402 style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_170402').style.display='none'; getElementById('Code_Closed_Image_170402').style.display='inline'; getElementById('Code_Closed_Text_170402').style.display='inline';" height=16 src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" width=11 align=top><SPAN class=cnblogs_code_Collapse id=Code_Closed_Text_170402>Code</SPAN><SPAN id=Code_Open_Text_170402 style="DISPLAY: none"><BR><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;AccessPath&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Application.StartupPath.ToString()&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">\\</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">SAP_Words.dll</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;ResourcesPath&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;Application.StartupPath.ToString()&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">\\</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">Resources.dll</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 調用 <STRONG><FONT style="BACKGROUND-COLOR: #ffffff" color=#ff0000>WriteEmbeddedFile("SAP_Words.dll", AccessPath);</FONT></STRONG><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;Stream&nbsp;GetStream(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;name)<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_257_354_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_257_354_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_257_354_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_257_354_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_257_354_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_257_354_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_257_354_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_257_354_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_257_354_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_257_354_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;GetResourceAssembly().GetManifestResourceStream(</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #800000">資源類的命名空間.</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">name);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;Assembly&nbsp;GetResourceAssembly()<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_411_475_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_411_475_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_411_475_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_411_475_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_411_475_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_411_475_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_411_475_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_411_475_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_411_475_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_411_475_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;Assembly.LoadFrom(ResourcesPath);<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;WriteEmbeddedFile(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;name,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;fileName)<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_554_1045_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_554_1045_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_554_1045_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_554_1045_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_554_1045_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_554_1045_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_554_1045_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_554_1045_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_554_1045_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_554_1045_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;(Stream&nbsp;stream&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;GetStream(name))<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_620_1035_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_620_1035_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_620_1035_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_620_1035_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_620_1035_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_620_1035_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_620_1035_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_620_1035_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_620_1035_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_620_1035_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInfo&nbsp;file&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;FileInfo(fileName);<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;(FileStream&nbsp;fileStream&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;file.Create())<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_756_1021_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_756_1021_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_756_1021_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_756_1021_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_756_1021_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_756_1021_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_756_1021_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_756_1021_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_756_1021_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_756_1021_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">[]&nbsp;buf&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #800080">1024</SPAN><SPAN style="COLOR: #000000">];<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;size;<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">&nbsp;((size&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;stream.Read(buf,&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #800080">1024</SPAN><SPAN style="COLOR: #000000">))&nbsp;</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">)<BR></SPAN><SPAN style="COLOR: #008080">25</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_924_1003_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_924_1003_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_924_1003_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_924_1003_Closed_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_924_1003_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_924_1003_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_924_1003_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_924_1003_Open_Text').style.display='inline';" src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_924_1003_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnblogs.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_924_1003_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">26</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileStream.Write(buf,&nbsp;</SPAN><SPAN style="COLOR: #800080">0</SPAN><SPAN style="COLOR: #000000">,&nbsp;size);<BR></SPAN><SPAN style="COLOR: #008080">27</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">28</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">29</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">30</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">31</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnblogs.com/images/OutliningIndicators/None.gif" align=top></SPAN></SPAN></DIV><img src ="http://www.cnblogs.com/godwar/aggbug/1276842.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42100/" target="_blank">[新闻]2008年9月5日科技博客精选</a>]]></description></item><item><title>微软Photosynth网站因流量过多陷入瘫痪</title><link>http://www.cnblogs.com/godwar/archive/2008/08/23/1274763.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Sat, 23 Aug 2008 09:41:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/23/1274763.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1274763.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/23/1274763.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1274763.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1274763.html</trackback:ping><description><![CDATA[<H2><FONT color=#333333></FONT>&nbsp;</H2>
<DIV id=text_content>
<P>　　北京时间8月22日消息，据国外媒体报道，微软新版数字图片共享网站Photosynth周三晚正式对外开放后，因用户访问量过多，导致该服务于周四早上一度中断。</P>
<P>　　利用Photosynth服务，用户可把内容相关的数字图片组合到一起，并可对图片局部进行放大或加亮，还可实现对图片的多角度浏览。在此之前，微软与美国《国家地理》杂志等合作伙伴联手开发了Photosynth服务，并为此推出了内部测试版。本周三，微软把Photosynth网站对外开放。但周四早上，由于访问Photosynth的用户过多，导致该网站无法正常访问。</P>
<P>　　微软Photosynth技术团队一位工程师周四表示，公司正对网站进行扩容，以使Photosynth服务尽早恢复正常。微软Live实验室主管之一戴维·吉迪(David Gedye)周二曾表示，由于网民对Photosynth期待很高，估计该网站正式对外开放后，开始数天内将面临巨大流量压力。</P>
<P>　　据Photosynth网站上的介绍，用户要想使用该服务，需首先安装Photosynth软件。该服务的操作系统环境为Windows XP和Vista，浏览器要求为IE 7、Firefox 2或Firefox 3。</P></DIV><img src ="http://www.cnblogs.com/godwar/aggbug/1274763.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42099/" target="_blank">[新闻]SNS网站风靡影响工作效率 公司下令封杀</a>]]></description></item><item><title>关于Debug和Release的区别之讨论</title><link>http://www.cnblogs.com/godwar/archive/2008/08/22/1274035.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Fri, 22 Aug 2008 06:08:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/22/1274035.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1274035.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/22/1274035.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1274035.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1274035.html</trackback:ping><description><![CDATA[<H5 class=posthead>&nbsp;</H5>
<DIV class=postText>关于Debug和Release的区别之讨论本文主要包含如下内容：<BR><BR><STRONG>1. Debug 和 Release 编译方式的本质区别<BR>2. 哪些情况下 Release 版会出错<BR>2. 怎样“调试” Release 版的程序 <BR></STRONG>
<P><BR><STRONG>一、Debug 和 Release 编译方式的本质区别<BR></STRONG>Debug 通常称为调试版本，它包含调试信息，并且不作任何优化，便于程序员调试程<BR>序。Release 称为发布版本，它往往是进行了各种优化，使得程序在代码大小和运行速度<BR>上都是最优的，以便用户很好地使用。<BR>Debug 和 Release 的真正秘密，在于一组编译选项。下面列出了分别针对二者的选项<BR>（当然除此之外还有其他一些，如/Fd /Fo，但区别并不重要，通常他们也不会引起 Rele<BR>ase 版错误，在此不讨论）<BR>Debug 版本：<BR>/MDd /MLd 或 /MTd 使用 Debug runtime library(调试版本的运行时刻函数库)<BR>/Od 关闭优化开关<BR>/D "_DEBUG" 相当于 #define _DEBUG,打开编译调试代码开关(主要针对<BR>assert函数)<BR>/ZI 创建 Edit and continue(编辑继续)数据库，这样在调试过<BR>程中如果修改了源代码不需重新编译<BR>/GZ 可以帮助捕获内存错误<BR>/Gm 打开最小化重链接开关，减少链接时间</P>
<P>Release 版本：<BR>/MD /ML 或 /MT 使用发布版本的运行时刻函数库<BR>/O1 或 /O2 优化开关，使程序最小或最快<BR>/D "NDEBUG" 关闭条件编译调试代码开关(即不编译assert函数)<BR>/GF 合并重复的字符串，并将字符串常量放到只读内存，防止<BR>被修改<BR>实际上，Debug 和 Release 并没有本质的界限，他们只是一组编译选项的集合，编译<BR>器只是按照预定的选项行动。事实上，我们甚至可以修改这些选项，从而得到优化过的调<BR>试版本或是带跟踪语句的发布版本。</P>
<P><STRONG>二、哪些情况下 Release 版会出错</STRONG></P>
<P>有了上面的介绍，我们再来逐个对照这些选项看看 Release 版错误是怎样产生的</P>
<P>1. Runtime Library：</P>
<P>2. 优化：这类错误主要有以下几种：</P>
<P>(1) 帧指针(Frame Pointer)省略（简称 FPO ）：在函数调用过程中，所有调用信息<BR>（返回地址、参数）以及自动变量都是放在栈中的。若函数的声明与实现不同（参数、返<BR>回值、调用方式），就会产生错误————但 Debug 方式下，栈的访问通过 EBP 寄存器<BR>保存的地址实现，如果没有发生数组越界之类的错误（或是越界“不多”），函数通常能<BR>正常执行；Release 方式下，优化会省略 EBP 栈基址指针，这样通过一个全局指针访问栈<BR>就会造成返回地址错误是程序崩溃。C++ 的强类型特性能检查出大多数这样的错误，但如<BR>果用了强制类型转换，就不行了。你可以在 Release 版本中强制加入 /Oy- 编译选项来关<BR>掉帧指针省略，以确定是否此类错误。<BR>(2) volatile 型变量：volatile 告诉编译器该变量可能被程序之外的未知方式修改<BR>（如系统、其他进程和线程）。</P>
<P>(3) 变量优化：优化程序会根据变量的使用情况优化变量。例如，函数中有一个未被<BR>使用的变量，在 Debug 版中它有可能掩盖一个数组越界，而在 Release 版中，这个变量<BR>很可能被优化调，此时数组越界会破坏栈中有用的数据。当然，实际的情况会比这复杂得<BR>多。与此有关的错误有：</P>
<P>3. _DEBUG 与 NDEBUG ：当定义了 _DEBUG 时，assert() 函数会被编译，而 NDEBUG 时不<BR>被编译。除此之外，VC++中还有一系列断言宏。这包括：</P>
<P>ANSI C 断言 void assert(int expression );<BR>C Runtime Lib 断言 _ASSERT( booleanExpression );<BR>_ASSERTE( booleanExpression );<BR>MFC 断言 ASSERT( booleanExpression );<BR>VERIFY( booleanExpression );<BR>ASSERT_VALID( pObject );<BR>ASSERT_KINDOF( classname, pobject );<BR>ATL 断言 ATLASSERT( booleanExpression );<BR>此外，TRACE() 宏的编译也受 _DEBUG 控制。</P>
<P>4. /GZ 选项：这个选项会做以下这些事</P>
<P>(1) 初始化内存和变量。<BR>(2) 通过函数指针调用函数时，会通过检查栈指针验证函数调用的匹配性。（防止原<BR>形不匹配）<BR>(3) 函数返回前检查栈指针，确认未被修改.</P>
<P><STRONG>三、怎样“调试” Release 版的程序</STRONG></P>
<P>1. 前面已经提过，Debug 和 Release 只是一组编译选项的差别，实际上并没有什么<BR>定义能区分二者。我们可以修改 Release 版的编译选项来缩小错误范围。如上所述，可以<BR>把 Release 的选项逐个改为与之相对的 Debug 选项，如 /MD 改为 /MDd、/O1 改为 /Od<BR>，或运行时间优化改为程序大小优化。注意，一次只改一个选项，看改哪个选项时错误消<BR>失，再对应该选项相关的错误，针对性地查找。这些选项在 Project\Settings... 中都可<BR>以直接通过列表选取，通常不要手动修改。由于以上的分析已相当全面，这个方法是最有<BR>效的。<BR>2.你也可以像 Debug 一样调试你的 Release 版，只要加入调试符号。在 Project/S<BR>ettings... 中，选中 Settings for "Win32 Release"，选中 C/C++ 标签，Category 选<BR>General，Debug Info 选 Program Database。再在 Link 标签 Project options 最后<BR>加上 "/OPT:REF" (引号不要输)。</P></DIV><img src ="http://www.cnblogs.com/godwar/aggbug/1274035.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/42098/" target="_blank">[新闻]《孢子》正式发布</a>]]></description></item><item><title>【ZT】delegate 与 多线程</title><link>http://www.cnblogs.com/godwar/archive/2008/08/22/1273724.html</link><dc:creator>巍巍边疆</dc:creator><author>巍巍边疆</author><pubDate>Fri, 22 Aug 2008 01:14:00 GMT</pubDate><guid>http://www.cnblogs.com/godwar/archive/2008/08/22/1273724.html</guid><wfw:comment>http://www.cnblogs.com/godwar/comments/1273724.html</wfw:comment><comments>http://www.cnblogs.com/godwar/archive/2008/08/22/1273724.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/godwar/comments/commentRss/1273724.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/godwar/services/trackbacks/1273724.html</trackback:ping><description><![CDATA[<TABLE cellPadding=4 width=600 border=0>
<TBODY>
<TR>
<TD height=19>
<TABLE cellSpacing=3 cellPadding=3 width=600 bgColor=#eeeeee border=0>
<TBODY>
<TR>
<TD noWrap align=middle bgColor=#003399 height=16><FONT color=#ffffff>标题</FONT></TD>
<TD><B>&nbsp; <SPAN id=ArticleTitle1_ArticleTitle1_lblTitle>delegate 与 多线程</SPAN></B>&nbsp;&nbsp;&nbsp;&nbsp; 选择自 <A id=ArticleTitle1_ArticleTitle1_AuthorLink href="http://dev.csdn.net/user/cpXparco">cpXparco</A> 的 Blog </TD></TR>
<TR>
<TD align=middle bgColor=#003399 height=16><FONT color=#ffffff>关键字</FONT></TD>
<TD width=500>&nbsp; <SPAN id=ArticleTitle1_ArticleTitle1_lblKeywords>delegate 与 多线程</SPAN></TD></TR>
<TR>
<TD align=middle bgColor=#003399 height=16><FONT color=#ffffff>出处</FONT></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><SPAN id=ArticleContent1_ArticleContent1_lblContent>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">很多时候写</SPAN><SPAN lang=EN-US>windows</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序都需要结合多线程，在</SPAN><SPAN lang=EN-US>.net</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中用如下得代码来创建并启动一个新的线程。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">public</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> <SPAN style="COLOR: blue">void</SPAN> ThreadProc();<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">Thread thread = <SPAN style="COLOR: blue">new</SPAN> Thread( <SPAN style="COLOR: blue">new</SPAN> ThreadStart( ThreadProc ) );<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">thread.IsBackground = <SPAN style="COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">thread.Start();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但是很多时候，在新的线程中，我们需要与</SPAN><SPAN lang=EN-US>UI</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行交互，在</SPAN><SPAN lang=EN-US>.net</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中不允许我们直接这样做。可以参考</SPAN><SPAN lang=EN-US>MSDN</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的描述：</SPAN></P>
<P><FONT face=宋体><SPAN lang=EN-US style="FONT-SIZE: 9pt">“Windows </SPAN><SPAN style="FONT-SIZE: 9pt">窗体<SPAN lang=EN-US>”</SPAN>使用单线程单元<SPAN lang=EN-US> (STA) </SPAN>模型，因为<SPAN lang=EN-US>“Windows </SPAN>窗体<SPAN lang=EN-US>”</SPAN>基于本机<SPAN lang=EN-US> Win32 </SPAN>窗口，而<SPAN lang=EN-US> Win32 </SPAN>窗口从本质上而言是单元线程。<SPAN lang=EN-US>STA </SPAN>模型意味着可以在任何线程上创建窗口，但窗口一旦创建后就不能切换线程，并且对它的所有函数调用都必须在其创建线程上发生。除了<SPAN lang=EN-US> Windows </SPAN>窗体之外，<SPAN lang=EN-US>.NET Framework </SPAN>中的类使用自由线程模型。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P><FONT face=宋体><SPAN lang=EN-US style="FONT-SIZE: 9pt">STA </SPAN><SPAN style="FONT-SIZE: 9pt">模型要求需从控件的非创建线程调用的控件上的任何方法必须被封送到（在其上执行）该控件的创建线程。基类<SPAN lang=EN-US> Control </SPAN>为此目的提供了若干方法（<SPAN lang=EN-US>Invoke</SPAN>、<SPAN lang=EN-US>BeginInvoke </SPAN>和<SPAN lang=EN-US> EndInvoke</SPAN>）。<B><SPAN lang=EN-US>Invoke</SPAN></B><SPAN lang=EN-US> </SPAN>生成同步方法调用；<B><SPAN lang=EN-US>BeginInvoke</SPAN></B><SPAN lang=EN-US> </SPAN>生成异步方法调用。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P><FONT face=宋体><SPAN lang=EN-US style="FONT-SIZE: 9pt">Windows </SPAN><SPAN style="FONT-SIZE: 9pt">窗体中的控件被绑定到特定的线程，不具备线程安全性。因此，如果从另一个线程调用控件的方法，那么必须使用控件的一个<SPAN lang=EN-US> Invoke </SPAN>方法来将调用封送到适当的线程。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">正如所看到的，我们必须调用</SPAN><SPAN lang=EN-US>Invoke</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法，而</SPAN><SPAN lang=EN-US>BeginInvoke</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以认为是</SPAN><SPAN lang=EN-US>Invoke</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的异步版本。调用方法如下：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">public</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> <SPAN style="COLOR: blue">delegate</SPAN> <SPAN style="COLOR: blue">void</SPAN> OutDelegate(<SPAN style="COLOR: blue">string</SPAN> text);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">public</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"> <SPAN style="COLOR: blue">void</SPAN> OutText(<SPAN style="COLOR: blue">string</SPAN> text)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>txt.AppendText(text);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>txt.AppendText( "\t\n" );<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">OutDelegate outdelegate = <SPAN style="COLOR: blue">new</SPAN> OutDelegate( OutText );<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">this</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">.BeginInvoke(outdelegate, <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: blue">object</SPAN>[]{text});<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果我们需要在另外一个线程里面对</SPAN><SPAN lang=EN-US>UI</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行操作，我们需要一个类似</SPAN><SPAN lang=EN-US>OutText</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的函数，还需要一个该函数的委托</SPAN><SPAN lang=EN-US>delegate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，当然，这里展示的是自定义的，</SPAN><SPAN lang=EN-US>.net</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中还有很多其他类型的委托，可以直接使用，不需要而外声明。例如：</SPAN><SPAN lang=EN-US>MethodInvoker</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>EventHandler</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii