Events in C Sharp

Elaborate events in C Sharp .

In object-oriented languages, objects expose encapsulated functions called methods. Methods are encapsulated functions which run when they are invoked. Sometimes, however, we think of the process of method invocation more grandly. In such a case, the method invocation is termed an 'event', and the running of the method is the 'handling' of the event. An standard example of an event is a user's selection of a button on a graphical user interface; this action may trigger a number of methods to 'handle' it

Events provide a way for a class or object to notify other classes or objects when something of interest happens. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.

Even modeling is fully based the delegate model of C# language. According to the event modeling, publishers send out their event only to subscribers who have subscribed to receive the specific event.

Events have the following properties:

• The publisher determines when an event is raised, the subscribers determine what action is taken is response to the event.

• An event can have multiple subscribers. A subscriber can handle multiple events from multiple publishers.

• Events that the have no subscriber are never called.

• Events are commonly used to signal user actions such as button clicks or menu selection in graphical user interface.

• When an event has multiple subscribers, the event handlers are invoked synchronously when an event is raised.

• Events can be used to synchronize threads.

• In the .NET framework class library, events are based on the Event Handler delegate and the EventArgs base class.

Delegates (in particular multicast delegates) are essential in realizing this subscription notification model.

 

Leave Comment

Important Topics

Title
Terminologies in C Sharp
Introduction to C Sharp
Hello World Program
C vs C Sharp
C Sharp vs C Plus Plus
C SHARP vs JAVA
Array and Types of Array
Programs - Sum of all numbers in Array
Strings and Types of Strings
Delegates in C sharp
System Collection Generic
System.Collections Classes
System.Collections.Concurrent
Dot Net Assembly
Events in C Sharp