Definition of events in C#:
A class or object can notify other classes or objects of what has happened through events. The class that sends (or causes) the event is called the "issuer" and the class that receives (or processes) the event is called the "subscriber".
Events have the following characteristics:
- The publisher determines when to raise the event, and the subscriber determines what action to perform in response to the event.
- An event can have multiple subscribers. A subscriber can handle multiple events from multiple issuers.
- Events without subscribers are never called.
- Events are often used to inform users of actions, such as button clicks or menu selection actions in graphical user interfaces.
- If an event has multiple subscribers, multiple event handlers are called simultaneously when the event is raised. To call events asynchronously, see Calling Synchronization Methods Using Asynchronous.
- Event synchronization threads can be leveraged.
The event keyword is used to declare events in the publisher class.
ms link:The hyperlink login is visible.
There is actually no difference between event writing method A and writing method B!
You can refer to:The hyperlink login is visible.
EventHandler<T>Represents a method that accepts two parameters (object sender, TEventArgs e) and returns a void type. where TEventArgs must be a type derived from the EventArgs class. The latter parameter is used to store the parameters required for the event.
EventArgsis the base class of a class that contains event data, which does not contain event data, and is used by events that do not pass state information to the event handler when the event is raised. If the event handler needs state information, the application must derive a class from this class to hold the data.
Volatile.Read .NET 4.0 is not supported
// Summary: Object references read from the specified field. When it is needed on the system, a memory barrier will be inserted to prevent the processor from reordering memory operations, as shown below: If this method appears in the code after performing a read/write, the processor cannot move it before this method. // Parameters: // location: fields to read. // Type parameters: // T: The type of field to be read. This must be the reference type, not the value type. // Return results: Read to the reference T. This reference is written by any processor in the computer, regardless of the number of processors or the state of the processor cache. [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SecuritySafeCritical] [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] public static T Read<T>(ref T location) where T : class;
|