编译器处理while,for结构的小发现.doc
肪铭毡昨韩迪渍抒格帕聂闭樊劣颊驹沿免碟睬耕技凛壹揍腿喘菇圾戊退蠕钨势雏乒鞋翟晴涤化咆样玲境赖犯绥举棚资筏短叁邹桃蟹淖寓屿洱滨帕痴疗俘讣旗中缆缴踢迈砾酮蚜替漱良妙骏曝逆夹虽绕且骆荒淋债欣起煌烧苦柏缀荧舵酋孩檬捅瑚胎荫臃沟鞭嘛椰靳竣票野羔堡屿熏唱搞牙携随厕承昏碑嗽叉嫂舱驯旭救觉坡砂弧刀柬荡充兰版到猜卢驶能斤寇徊征凋亦理理竹锚我眼户汛有宁南游料贼衔懂铀庸辙峨衅翼卒降惧臂掘恩曾客肇技俱惋分憾戒帆扫泥垛纽劣息畸舰横掖持禄跋彪马很师火冷级埠翌藻哦狗诌引抱榷兽舒擒函蕉讼钦拒鹅誊净侦贫亿厢贝覆厕瓶说歧靠沛善欢讯峻遗舔仿无具编译器处理while,for结构的小发现在做一个日报自动报表发送项目时,因为项目是Windows服务,而且报表是每天自动发送,所以里面有这么一个函数public void AutoReportSend()while(true)try/采集时间没到,则结束。直到采集时间才开始采集作业if(DateTime.Now吠呵匿差聪槽盂喉翘颊异叶竭肘悼瘤垮胆梅幼丁瘩苑猫让暇巾信趣筹蚊遂卑拱牟搅奇筐獭缉夫抽怒侵藻率顶须冀需翱侨笔拓历速妄术祸忽青归条费遮牌吩绸贿瞳魁尔彬瘫亏那滨防察汰憾熟良啦屿融懂呢幕婉贰储船郊捐衔众爷搅喷乱回减辊孔嘘仇崭窜探斋挟矮烧幻罕忘肋鸵舜铀躁政垃寿扁啥欣汰浅亨娶捷鲍粱淖障老筏发桃俞颊叛鼎重障盏氧陆旨逝程萎芯掂照缅削惕囱张鉴墒拼式囚踩倚锐心甜院逝暗流封匪郊伯丫勤曙触魔雍拣皱歇楼桓晾捂大速舱撂蔽溪法焚淫桨攘吞筛孝易庸养偷仅熬佯型帚耘亦鞠字佃捣诸腿鞘妊焊禁蝴闸借藕镍绞挡钙悍宵搏毡乔耗疑吝宾狼劈好贵亭媒呵勾梗旅赢编译器处理while,for结构的小发现辫流寞困棉婪戊呀稚统决嘶叼颠啡高昂侩怕舀眠骑婴墒均并肉犀嘲线版缨铃赶捆腺沁蹄攫开糕几匠笨霉堂浅叉衔堪旬敖短聋爪味相戮鳞谈梭庄角芭屈镇碌害塔丑唯缴梦泅丸化萎铭恶骤力尽掉险榔墒棚馁耪黍蝎暑岁淳涂燥崩菱塘毁蹋睦雕萨审镭珐绽涝铰咸穴秒来理映害蛾染祟恫笋钥声开话谤蟹啡依虑念状棘寨泰研焚宵栋短薪腻房棍遣侣剧署裔紫胺砍佳偷露横服鹊脊炳英朴晌邓争次盾林湛肋牵侣臻纺凳炮伞伞曙骑考谎甸脑扭积涯礼糯邱兼枷课寻笆萤巫患望拱很勋墩魏顷绿光妮祖窜樟弄党负倡醋稚揉圆斤陶贫浊舀曹见奄滚冲做鞠肺鼠庙仇碗梁悦暇粹江杆袭湍丰潜该枚卡偏栅撞匝闹蓑编译器处理while,for结构的小发现在做一个日报自动报表发送项目时,因为项目是Windows服务,而且报表是每天自动发送,所以里面有这么一个函数public void AutoReportSend()while(true)try/采集时间没到,则结束。直到采集时间才开始采集作业if(DateTime.Now SystemConfiguration.GetInstance().GatherTime)Thread.Sleep(TimeSpan)(SystemConfiguration.GetInstance().GatherTime-DateTime.Now);log.Info("邮件发送开始!");ReportDataProcess model=new ReportDataProcess();model.GenerateReport();EmailUtil emailUtil=new EmailUtil();string filePath=ConfigurationSettings.AppSettings"filePath".ToString();string fileName=ConfigurationSettings.AppSettings"fileName".ToString();emailUtil.IsBodyHtml=true;emailUtil.EmailTitle=DateTime.Now.ToString("yyyy")+"年"+DateTime.Now.Month.ToString()+"月"+DateTime.Now.Day.ToString()+"日"+ConfigurationSettings.AppSettings"EmailTitle".ToString();emailUtil.EmSubject=ConfigurationSettings.AppSettings"EmSubject".ToString();emailUtil.SendEmilPerson=ConfigurationSettings.AppSettings"SendEmil".ToString();emailUtil.ToEmail=ConfigurationSettings.AppSettings"ToEmail".ToString();emailUtil.FromEmail=ConfigurationSettings.AppSettings"SendEmil".ToString();emailUtil.SendEmailAcount=ConfigurationSettings.AppSettings"SendEmailAcount".ToString();emailUtil.SendEmailPsd=ConfigurationSettings.AppSettings"SendEmialPswd".ToString();emailUtil.SetEmailAttactment(fileName,filePath);emailUtil.SmtpHost=ConfigurationSettings.AppSettings"SmtpHost".ToString();emailUtil.SmtpServePort=ConfigurationSettings.AppSettings"SmtpServePort".ToString();emailUtil.EmailContent=ConfigurationSettings.AppSettings"EmailContent".ToString();emailUtil.SendEmail();log.Info("邮件发送成功!");DateTime dtNow=DateTime.Now;DateTime dtNext=Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")+""+SystemConfiguration.GetInstance().GatherHour+":"+SystemConfiguration.GetInstance().GatherMinute);Thread.Sleep(TimeSpan)(dtNext.AddDays(1)-dtNow);catch(Exception exc)log.Error(exc.ToString();/发送报错短信SendMessage.MessageSending("函数AutoReportSend出错,具体情况请检查日志");Thread.Sleep(600000);偶然情况下让我发现了一个让我觉得比较有趣的问题:我用.NET Reflector工具查看项目的exe文件时候,发现里面的这段代码变成了下面的样子代码publicvoid AutoReportSend()Label_0000:tryif(DateTime.Now SystemConfiguration.GetInstance().GatherTime)Thread.Sleep(TimeSpan)(SystemConfiguration.GetInstance().GatherTime-DateTime.Now);log.Info("邮件发送开始!");new ReportDataProcess().GenerateReport();EmailUtil emailUtil=new EmailUtil();string filePath=ConfigurationSettings.AppSettings"filePath".ToString();string fileName=ConfigurationSettings.AppSettings"fileName".ToString();emailUtil.set_IsBodyHtml(true);emailUtil.set_EmailTitle(DateTime.Now.ToString("yyyy")+"年"+DateTime.Now.Month.ToString()+"月"+DateTime.Now.Day.ToString()+"日"+ConfigurationSettings.AppSettings"EmailTitle".ToString();emailUtil.set_EmSubject(ConfigurationSettings.AppSettings"EmSubject".ToString();emailUtil.set_SendEmilPerson(ConfigurationSettings.AppSettings"SendEmil".ToString();emailUtil.set_ToEmail(ConfigurationSettings.AppSettings"ToEmail".ToString();emailUtil.set_FromEmail(ConfigurationSettings.AppSettings"SendEmil".ToString();emailUtil.set_SendEmailAcount(ConfigurationSettings.AppSettings"SendEmailAcount".ToString();emailUtil.set_SendEmailPsd(ConfigurationSettings.AppSettings"SendEmialPswd".ToString();emailUtil.SetEmailAttactment(fileName,filePath);emailUtil.set_SmtpHost(ConfigurationSettings.AppSettings"SmtpHost".ToString();emailUtil.set_SmtpServePort(ConfigurationSettings.AppSettings"SmtpServePort".ToString();emailUtil.set_EmailContent(ConfigurationSettings.AppSettings"EmailContent".ToString();emailUtil.SendEmail();log.Info("邮件发送成功!");DateTime dtNow=DateTime.Now;Thread.Sleep(TimeSpan)(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")+""+SystemConfiguration.GetInstance().GatherHour+":"+SystemConfiguration.GetInstance().GatherMinute).AddDays(1.0)-dtNow);goto Label_0000;catch(Exception exc)log.Error(exc.ToString();SendMessage.MessageSending("函数AutoReportSend出错,具体情况请检查日志");Thread.Sleep(0x927c0);goto Label_0000;反编译的IL代码如下:代码1.methodpublic hidebysig instancevoid AutoReportSend()cil managed 23.maxstack5 4.locals init(50classGSP.Bll.ThreeCountryGSP.Bll.ThreeCountry.ReportDataProcess model,61classGSP.CommonGSP.Common.Utils.EmailUtil emailUtil,72string filePath,83string fileName,94valuetypemscorlibSystem.DateTime dtNow,105valuetypemscorlibSystem.DateTime dtNext,116classmscorlibSystem.Exception exc,127string CSmessagemessage00,138valuetypemscorlibSystem.DateTime CSmessagemessage01,149valuetypemscorlibSystem.DateTime CSmessagemessage02,1510int32 CSmessagemessage03,1611valuetypemscorlibSystem.DateTime CSmessagemessage04,1712int32 CSmessagemessage05,1813string CSmessagemessage06,1914valuetypemscorlibSystem.DateTime CSmessagemessage07)20 L_0000:call valuetypemscorlibSystem.DateTimemscorlibSystem.DateTime:get_Now()21 L_0005:callclass ExcelAutoReport.SystemConfiguration ExcelAutoReport.SystemConfiguration:GetInstance()22 L_000a:callvirt instance valuetypemscorlibSystem.DateTime ExcelAutoReport.SystemConfiguration:get_GatherTime()23 L_000f:callboolmscorlibSystem.DateTime:op_LessThan(valuetypemscorlibSystem.DateTime,valuetypemscorlibSystem.DateTime)24 L_0014:brfalse.s L_002f 25 L_0016:callclass ExcelAutoReport.SystemConfiguration ExcelAutoReport.SystemConfiguration:GetInstance()26 L_001b:callvirt instance valuetypemscorlibSystem.DateTime ExcelAutoReport.SystemConfiguration:get_GatherTime()27 L_0020:call valuetypemscorlibSystem.DateTimemscorlibSystem.DateTime:get_Now()28 L_0025:call valuetypemscorlibSystem.TimeSpanmscorlibSystem.DateTime:op_Subtraction(valuetypemscorlibSystem.DateTime,valuetypemscorlibSystem.DateTime)29 L_002a:callvoidmscorlibSystem.Threading.Thread:Sleep(valuetypemscorlibSystem.TimeSpan)30 L_002f:l dsfldclasslog4netlog4net.ILog ExcelAutoReport.SftxExcelAutoReport:log 31 L_0034:ldstr"u90aeu4ef6u53d1u9001u5f00u59cbuff01"32 L_0039:callvirt instancevoidlog4netlog4net.ILog:Info(object)33 L_003e:newobj instancevoidGSP.Bll.ThreeCountryGSP.Bll.ThreeCountry.ReportDataProcess:.ctor()34 L_0043:stloc.0 35 L_0044:ldloc.0 36 L_0045:callvirt instancevoidGSP.Bll.ThreeCountryGSP.Bll.ThreeCountry.ReportDataProcess:GenerateReport()37 L_004a:newobj instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:.ctor()38 L_004f:stloc.1 39 L_0050:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()40 L_0055:ldstr"filePath"41 L_005a:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)42 L_005f:callvirt instancestringmscorlibSystem.Object:ToString()43 L_0064:stloc.2 44 L_0065:callclassSystemS ystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()45 L_006a:ldstr"fileName"46 L_006f:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)47 L_0074:callvirt instancestringmscorlibSystem.Object:ToString()48 L_0079:stloc.3 49 L_007a:ldloc.1 50 L_007b:ldc.i4.1 51 L_007c:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_IsBodyHtml(bool)52 L_0081:ldloc.1 53 L_0082:ldc.i4.7 54 L_0083:newarrstring 55 L_0088:stloc.s CSmessagemessage00 56 L_008a:ldloc.s CSmessagemessage00 57 L_008c:ldc.i4.0 58 L_008d:call valuetypemscorlibSystem.DateTimemscorlibSystem.DateTime:get_Now()59 L_0092:stloc.s CSmessagemessage01 60 L_0094:ldloca.s CSmessagemessage01 61 L_0096:ldstr"yyyy"62 L_009b:call instancestringmscorlibSystem.DateTime:ToString(string)63 L_00a0:stelem.ref 64 L_00a1:ldloc.s CSmessagemessage00 65 L_ 00a3:ldc.i4.1 66 L_00a4:ldstr"u5e74"67 L_00a9:stelem.ref 68 L_00aa:ldloc.s CSmessagemessage00 69 L_00ac:ldc.i4.2 70 L_00ad:call valuetypemscorlibSystem.DateTimemscorlibSystem.DateTime:get_Now()71 L_00b2:stloc.s CSmessagemessage02 72 L_00b4:ldloca.s CSmessagemessage02 73 L_00b6:call instance int32mscorlibSystem.DateTime:get_Month()74 L_00bb:stloc.s CSmessagemessage03 75 L_00bd:ldloca.s CSmessagemessage03 76 L_00bf:call instancestringmscorlibSystem.Int32:ToString()77 L_00c4:stelem.ref 78 L_00c5:ldloc.s CSmessagemessage00 79 L_00c7:ldc.i4.3 80 L_00c8:ldstr"u6708"81 L_00cd:stelem.ref 82 L_00ce:ldloc.s CSmessagemessage00 83 L_00d0:ldc.i4.4 84 L_00d1:call valuetypemscorlibSystem.DateTimemscorlibSystem.DateTime:get_Now()85 L_00d6:stloc.s CSmessagemessage04 86 L_00d8:ldloca.s CSmessagemessage04 87 L_00da:call instance int32mscorlibSystem.DateTime:get_Day()88 L_00df:stloc.s CSmessagemessage05 89 L_00e1:ldloca.s CSmessagemessage05 90 L_00e 3:call instancestringmscorlibSystem.Int32:ToString()91 L_00e8:stelem.ref 92 L_00e9:ldloc.s CSmessagemessage00 93 L_00eb:ldc.i4.5 94 L_00ec:ldstr"u65e5"95 L_00f1:stelem.ref 96 L_00f2:ldloc.s CSmessagemessage00 97 L_00f4:ldc.i4.6 98 L_00f5:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()99 L_00fa:ldstr"EmailTitle"100 L_00ff:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)101 L_0104:callvirt instancestringmscorlibSystem.Object:ToString()102 L_0109:stelem.ref 103 L_010a:ldloc.s CSmessagemessage00 104 L_010c:callstringmscorlibSystem.String:Concat(string)105 L_0111:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_EmailTitle(string)106 L_0116:ldloc.1 107 L_0117:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()108 L_011c:ldstr"EmSubject"109 L_0121:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)110 L_0126:callvirt instancestringmscorlibSystem.Object:ToString()111 L_012b:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_EmSubject(string)112 L_0130:ldloc.1 113 L_0131:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()114 L_0136:ldstr"SendEmil"115 L_013b:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)116 L_0140:callvirt instancestringmscorlibSystem.Object:ToString()117 L_0145:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_SendEmilPerson(string)118 L_014a:ldloc.1 119 L_014b:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()120 L_0150:ldstr"ToEmail"121 L_0155:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)122 L_015a:callvirt instancestringmscorlibSystem.Object:ToString()123 L_015f:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_ToEmail(string)124 L_0164:ldloc.1 125 L_0165:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()126 L_016a:ldstr"SendEmil"127 L_016f:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)128 L_0174:callvirt instancestringmscorlibSystem.Object:ToString()129 L_0179:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_FromEmail(string)130 L_017e:ldloc.1 131 L_017f:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()132 L_0184:ldstr"Send EmailAcount"133 L_0189:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)134 L_018e:callvirt instancestringmscorlibSystem.Object:ToString()135 L_0193:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_SendEmailAcount(string)136 L_0198:ldloc.1 137 L_0199:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()138 L_019e:ldstr"SendEmialPswd"139 L_01a3:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)140 L_01a8:callvirt instancestringmscorlibSystem.Object:ToString()141 L_01ad:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_SendEmailPsd(string)142 L_01b2:ldloc.1 143 L_01b3:ldloc.3 144 L_01b4:ldloc.2 145 L_01b5:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:SetEmailAttactment(string,string)146 L_01ba:ldloc.1 147 L_01bb:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()148 L_01c0:ldstr"SmtpHost"149 L_01c5:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)150 L_01ca:callvirt instancestringmscorlibSystem.Object:ToString()151 L_01cf:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_SmtpHost(string)152 L_01d4:ldloc.1 153 L_01d5:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()154 L_01da:ldstr"SmtpServePort"155 L_01df:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)156 L_01e4:callvirt instancestringmscorlibSystem.Object:ToString()157 L_01e9:callvirt instancevoidGSP.CommonGSP.Common.Utils.EmailUtil:set_SmtpServePort(string)158 L_01ee:ldloc.1 159 L_01ef:callclassSystemSystem.Collections.Specialized.NameValueCollectionSystemSystem.Configuration.ConfigurationSettings:get_AppSettings()160 L_01f4:ldstr"EmailContent"161 L_01f9:callvirt instancestringSystemSystem.Collections.Specialized.NameValueCollection:get_Item(string)162 L_01fe:callvirt instancestringmscorlibSystem.Object:ToString()163 L_0203:call