[WEBINAR] Bulletproof: How Today's Business Leaders Stay on Top

Event Handler

Definition - What does Event Handler mean?

An event handler, in C#, is a method that contains the code that gets executed in response to a specific event that occurs in an application.

Event handlers are used in graphical user interface (GUI) applications to handle events such as button clicks and menu selections, raised by controls in the user interface. A single event handler can be used to process events raised by multiple controls. An event can be associated with multiple event handlers, which will be invoked synchronously when the even occurs. Event handlers can also be used to handle events that signal an object's state changes to the object's clients.

Techopedia explains Event Handler

The C# event model is based on a "publish-subscribe" pattern in which a class (publisher) triggers an event, while another class (subscriber) receives that event. An event handler is the subscriber that contains the code to handle specific events.

For example, an event handler can be used to handle an event that occurs during the click of a command button in the UI.

In C#, an event is connected to its handler by an event delegate. To raise an event and respond to the event, the two necessary elements are the delegate that links the event to its handler method and the class that holds event data. By adding the delegate instance to the event object using the addition assignment operator (‘+=’), the event handler is called on occurrence of its associated event.

The signature of an event handler delegate includes two parameters that represent the object instance raising the event and the object holding event data. The signature of an event handler method should match with that of the delegate for that event and with the return type as void. The .NET framework provides a built-in event handler that can be used in cases where the delegates used differ only by type name and hence can reduce code that needs to be maintained.

This definition was written in the context of C#
Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.