仓酷云
标题:
ASP.NET编程:一个完成自界说event的文章。。。我还没...
[打印本页]
作者:
愤怒的大鸟
时间:
2015-1-16 22:50
标题:
ASP.NET编程:一个完成自界说event的文章。。。我还没...
我认为,可以通过更加简单的首次编译,而增加第二次编译的负担,来提高java的运行效率。只是将java源代码进行简单的等价转换,而不假设编译成某种虚拟机器的目标格式,而由本地编译器针对性的二次编译。ThelatestofferingfromMicrosofttosupportsoftwaredevelopmentisthe.NETFramework.InsidethisvastFrameworkistheASP.NET.TheASP.NETfacilitatestheapplicationdevelopmentcommunityingeneratinghighperformanceWebbasedapplicationsthatcanbedatarichandworkinaheterogeneousenvironment.
Inthisdiscussionwewillexaminethestepstocreateacustomeventthatwillalerttheuserorprocessthateventhastakenplaceunderaspecifiedcondition.Tounderstandhowtosetupthecodestructuretoraiseandhandleevents,anoverviewoftheeventarchitectureisneeded.
EventArchitecture
Belowareanumberofkeypointsthatencompassthe.NetFrameworkeventmodel.
-Eventstakingplaceinthe.NETFrameworkarebaseduponthedelegatemodel.
-Thedelegateclassisthemechanismthatallowstheeventsendertocommunicatewiththeeventhandler.
-Aneventsendercanbroadcastaneventtoanumberofeventhandlers.
-Aneventhandlermustberegisteredwithaneventsender.
Thefundamentaldefinitionofaneventis:Aneventisamessagethathasbeensentbyanobjectduetosomeoccurrenceofanactionwithintheworkflowoftheapplication.Thisactioncouldbeabuttonthathasbeenclickedorspecifiedtimeoutparametervaluehasbeenreached.Thisactiontriggerstheeventandthesubsequentmethodthathandlestheeventisinitiatedandtheeventishandled.
Inthe.NETframework,thesendingobjectdoesnotknowwhatmethodwillhandletheevent.Therefore,anagentmustbeutilizedtohandlethecommunication.Thisagentisthedelegateclassthatholdsareferencetothemethodthathandlestheevent.Thedelegateclasshasanintrinsicsignatureandcanonlyholdreferencestomethodsthatobtainthesamesignature.Youcanequivocatethedelegateclasstoatype-safepointertoacallback.Theeventdelegatehastwoparameters;thesearethesendingobjectandthereturneddata.BelowinListing1isgenericdeclarationoftheeventdelegateclass.
Listing1
PublicdelegatevoidEventHandler(objectSender,EventArgse);
Inordertoinitiateandhandlecustomevents,eventfunctionalityneedstobeprovided.Thefundamentalstructureislistedasfollows:
-Aclasstoholdtheeventdata.ThismustbeinheritedfromSystem.EventArgs.
-Adelegatefortheevent.
-Aclassthatraisestheevent.
-Aclasswithamethodthathandlestheevent.
Nowthatwehavediscussedthefundamentalsofeventhandling,weneedasimpleapplicationtodepicttheeventfunctionality.
CustomEventsApplication
TheCustomEventsApplicationiscomprisedofasimpleWebFormthatdisplaystheeventdatamessage.ThisisshowninFigure1.
Figure1
Inordertoinitiatesomeactionthatshowsthefunctionalityofeventhandling,aloopiscreatedtocounttosomenumberandstop.Duringthiscount,aspecificvalueisinterrogatedwithintheloop.Whenthespecifiedvalueisequaltotheloopvalue,theeventisfired.Inthiscasethevalueis400000.Thelooprunsfrom1to500000.Whenthevalue400000isreachedtheOnMessagemethodiscalledandtheeventisraised.Note:TheInitEvent()methodiscalledfromPage_Load()methodwhenthepageisrequested.TheInitEvent()methodisdepictedinListing2.
Listing2
privatevoidInitEvent()
{
MessagingHandlermh=newMessagingHandler();
MessageEventme=newMessageEvent();
me.Message+=newMessageHandler(mh.GetMessageData);
for(inti=1;i<=500000;i++)
{
if(i==400000)
{
MessageEventArgse=newMessageEventArgs();
me.OnMessage(e);
lblMessage.Text=mh.EventMessage;
}
}
}
AsyoucanseethisiscertainlyoverkilltodisplayalineoftextinalabelfieldonaWebpage.However,itisusefultoexaminetheworkflowofaneventthatiscapturedandhandledinthe.NETFramework.InordertomakesenseofthecodefragmentinListing2,weneedtoexaminetheclassesthatcomprisetheeventstructure.BelowinListing3showstherespectivecomponentsthatwillraiseandhandletheeventasittranspires.
Listing3
publicclassMessageEventArgs:EventArgs
{
publicstringMessageText
{
get
{
return("Therehasbeen400000valuesprocessed.");
}
}
}
publicdelegatevoidMessageHandler(objectsender,MessageEventArgse);
publicclassMessageEvent
{
publiceventMessageHandlerMessage;
publicvoidOnMessage(MessageEventArgse)
{
if(Message!=null)
{
Message(this,e);
}
}
}
publicclassMessagingHandler
{
privatestringstrMessage;
publicstringEventMessage
{
get
{
returnstrMessage;
}
set
{
strMessage=value;
}
}
publicvoidGetMessageData(objectsender,MessageEventArgse)
{
stringstrMessage=e.MessageText;
EventMessage=strMessage;
}
}
TheclassMessageEventArgswillsupplythedataforevent.NoticethatitisinheritedfromEventArgs.AsyoucanseeMessageTextisapropertyoftheclassandagetstatementisutilizedtoreturnthedatastring.ThedelegateinthiscaseistheMessageHandler.IthasthesenderobjectandtheMessageEventArgsforthedatainitsargumentlist.MovingontotheclassMessageEvent.ThisclasswillraisetheeventwiththeOnMessage()methodbyinvokingthedelegates.TheMessagingHandlerclasswillextracttheeventmessagefromtheMessageEventArgsandpopulatetheEventMessagepropertysothemessagecanbedisplayedontheWebpage.
Insummarization,wehaveaclassthatsuppliesthedata,adelegatetoprovidethecommunication,aclasstoraisetheevent,andaclasstohandletheevent.Thebasicworkflowisasfollows:
-TheInitEvent()isinitiatedfromthePage_Load()methodwhenthepageisrequested.
-MessagingHandlermh=newMessagingHandler()instantiatestheMessagingHandlerclass-EventReceiver.
-MessageEventme=newMessageEvent()instantiatestheMessageEventclass-EventSender.
-me.Message+=newMessageHandler(mh.GetMessageData)registerstheeventhandlerwiththeeventsourcesothattheMessagingHandlerinstancecanreceivealarmevents.The+=assignmentoperatoraddsthedelegatetothelistofdelegatesthatareregisteredwiththeMessageevent.
-Whenthespecifiedvalueisreached,MessageEventArgse=newMessageEventArgs()isinstantiatedandtheOnMessage()iscalledtoraisetheevent.
-TheOnMessage()methodinvokesthedelegatewhichcallstheGetMessageData()methodtohandletheevent.
-TheGetMessageData()methodobtainsthemessagetextfromtheMessageEventArgsandpopulatestheEventMessagepropertywiththestringdata.
-ThelabelfieldispopulatedwiththeEventMessagestringpropertyvalueanddisplayedontheWebpage.
Runthisexample
[runit]
Conclusion
SinceWebbasedapplicationsaredisconnectedinnatureandthehandlingofeventsaretypicallyserver-sidetheeventmessageisdisplayedaftertheentirecodesequencehastranspired.Thisparadigmisnotconduciveforasynchronousprocessingduetothefire-and-forgetprocessing.However,theycanbeusefulifyouaredoingheavyserver-sideprocessingandvalidationbeforerenderingthepage.
The.NETFrameworkisprovidingtheapplicationdeveloperagreatdealofoptionstogeneratemeaningfulsolutionstotheenterprise,beitWebbasedapplications,WindowsClientbasedapplications,orServerbasedSer
[img=1border=0style=,1src=]http://www.ckuyun.com/[/img]
感觉很多控件都必须自己去写代码;用了WebMatrix感觉也不是很好,毕竟没有很强的WYSIWYG效果。现在就不知道如何是好了。
作者:
小魔女
时间:
2015-1-18 15:43
ASP.NET:ASP.net是Microsoft.net的一部分,作为战略产品,不仅仅是ActiveServerPage(ASP)的下一个版本;它还提供了一个统一的Web开发模型,其中包括开发人员生成企业级Web应用程序所需的各种服务。ASP.NET的语法在很大程度上与ASP兼容,同时它还提供一种新的编程模型和结构,可生成伸缩性和稳定性更好的应用程序,并提供更好的安全保护。
作者:
再现理想
时间:
2015-1-22 07:52
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
作者:
爱飞
时间:
2015-1-30 23:54
在一个项目中谁敢保证每天几千万甚至几亿条的数据不丢失?谁敢保证应用的高可靠性?有可以借签的项目吗?
作者:
谁可相欹
时间:
2015-2-6 17:17
它可通过内置的组件实现更强大的功能,如使用A-DO可以轻松地访问数据库。
作者:
仓酷云
时间:
2015-2-17 14:53
同时也感谢博客园给我们这个平台,也感谢博客园的编辑们做成专题引来这么多高人指点。
作者:
第二个灵魂
时间:
2015-3-5 20:24
asp.net空间的支持有:ASP.NET1.1/虚拟目录/MicrosoftFrontPage2000扩展/CDONTS,同时他的网站上也提供了Asp.net的使用详解和程序源代码,相信对使用ASP.NET编程的程序员来说会非常有用哦!
作者:
飘灵儿
时间:
2015-3-12 13:38
碰到复杂点的问题都不知道能不能解决,现在有点实力的公司都选择自已在开源的基础上做开发。但没听说过有人在IIS上做改进的,windows、sqlserver集群方面的应用也很少见。
作者:
蒙在股里
时间:
2015-3-19 22:34
PHP的源代码完全公开,在OpenSource意识抬头的今天,它更是这方面的中流砥柱。不断地有新的函数库加入,以及不停地更新,使得PHP无论在UNIX或是Win32的平台上都可以有更多新的功能。它提供丰富的函数,使得在程式设计方面有着更好的资源。目前PHP的最新版本为4.1.1,它可以在Win32以及UNIX/Linux等几乎所有的平台上良好工作。PHP在4.0版后使用了全新的Zend引擎,其在最佳化之后的效率,比较传统CGI或者ASP等技术有了更好的表现。
欢迎光临 仓酷云 (http://ckuyun.com/)
Powered by Discuz! X3.2