一个实现自定义event的文章。。。我还没有完全摸透。。不知道有没人有兴趣。。新手就不用看了,先学会

作者:袖梨 2022-07-02
The latest offering from Microsoft to support software development is the .NET Framework. Inside this vast Framework is the ASP.NET. The ASP.NET facilitates the application development community in generating high performance Web based applications that can be data rich and work in a heterogeneous environment.
In this discussion we will examine the steps to create a custom event that will alert the user or process that event has taken place under a specified condition. To understand how to setup the code structure to raise and handle events, an overview of the event architecture is needed.
Event Architecture
Below are a number of key points that encompass the .Net Framework event model.
- Events taking place in the .NET Framework are based upon the delegate model.
- The delegate class is the mechanism that allows the event sender to communicate with the event handler.
- An event sender can broadcast an event to a number of event handlers.
- An event handler must be registered with an event sender.
The fundamental definition of an event is: An event is a message that has been sent by an object due to some occurrence of an action within the workflow of the application. This action could be a button that has been clicked or specified timeout parameter value has been reached. This action triggers the event and the subsequent method that handles the event is initiated and the event is handled.
In the .NET framework, the sending object does not know what method will handle the event. Therefore, an agent must be utilized to handle the communication. This agent is the delegate class that holds a reference to the method that handles the event. The delegate class has an intrinsic signature and can only hold references to methods that obtain the same signature. You can equivocate the delegate class to a type-safe pointer to a callback. The event delegate has two parameters; these are the sending object and the returned data. Below in Listing 1 is generic declaration of the event delegate class.

相关文章

精彩推荐