仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1061|回复: 8
打印 上一主题 下一主题

[学习教程] ASP.NET编程:一个完成自界说event的文章。。。我还没...

[复制链接]
愤怒的大鸟 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:50:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
我认为,可以通过更加简单的首次编译,而增加第二次编译的负担,来提高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:54 | 只看该作者
ASP.NET:ASP.net是Microsoft.net的一部分,作为战略产品,不仅仅是ActiveServerPage(ASP)的下一个版本;它还提供了一个统一的Web开发模型,其中包括开发人员生成企业级Web应用程序所需的各种服务。ASP.NET的语法在很大程度上与ASP兼容,同时它还提供一种新的编程模型和结构,可生成伸缩性和稳定性更好的应用程序,并提供更好的安全保护。
再现理想 该用户已被删除
板凳
发表于 2015-1-22 07:52:32 | 只看该作者
以上是语言本身的弱点,在功能方面ASP同样存在问题,第一是功能太弱,一些底层操作只能通过组件来完成,在这点上是远远比不上PHP/JSP,其次就是缺乏完善的纠错/调试功能,这点上ASP/PHP/JSP差不多。
爱飞 该用户已被删除
地板
发表于 2015-1-30 23:54:36 | 只看该作者
在一个项目中谁敢保证每天几千万甚至几亿条的数据不丢失?谁敢保证应用的高可靠性?有可以借签的项目吗?
谁可相欹 该用户已被删除
5#
发表于 2015-2-6 17:17:47 | 只看该作者
它可通过内置的组件实现更强大的功能,如使用A-DO可以轻松地访问数据库。
6#
发表于 2015-2-17 14:53:11 | 只看该作者
同时也感谢博客园给我们这个平台,也感谢博客园的编辑们做成专题引来这么多高人指点。
第二个灵魂 该用户已被删除
7#
发表于 2015-3-5 20:24:48 | 只看该作者
asp.net空间的支持有:ASP.NET1.1/虚拟目录/MicrosoftFrontPage2000扩展/CDONTS,同时他的网站上也提供了Asp.net的使用详解和程序源代码,相信对使用ASP.NET编程的程序员来说会非常有用哦!
飘灵儿 该用户已被删除
8#
发表于 2015-3-12 13:38:56 | 只看该作者
碰到复杂点的问题都不知道能不能解决,现在有点实力的公司都选择自已在开源的基础上做开发。但没听说过有人在IIS上做改进的,windows、sqlserver集群方面的应用也很少见。
蒙在股里 该用户已被删除
9#
发表于 2015-3-19 22:34:43 | 只看该作者
PHP的源代码完全公开,在OpenSource意识抬头的今天,它更是这方面的中流砥柱。不断地有新的函数库加入,以及不停地更新,使得PHP无论在UNIX或是Win32的平台上都可以有更多新的功能。它提供丰富的函数,使得在程式设计方面有着更好的资源。目前PHP的最新版本为4.1.1,它可以在Win32以及UNIX/Linux等几乎所有的平台上良好工作。PHP在4.0版后使用了全新的Zend引擎,其在最佳化之后的效率,比较传统CGI或者ASP等技术有了更好的表现。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-24 07:37

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表