System.Reflection.EventInfo.AddEventHandler Method

Adds an event handler to an event source.

Syntax

[System.Diagnostics.DebuggerStepThrough]
public virtual void AddEventHandler (object target, Delegate handler)

Parameters

target
The event source.
handler
Encapsulates a method or methods to be invoked when the event is raised by the target.

Exceptions

TypeReason
ArgumentException handler is not the same Type as the event handler delegate declared for the event reflected by the current instance.
System.Reflection.TargetExceptionThe event reflected by the current instance is non-static, and obj is null or is of a type that does not implement the event reflected by the current instance.

Remarks

This method attempts to add a delegate to synchronize the event on the target object.

Each time the event is raised by the target parameter, the method or methods encapsulated by the handler will be invoked.

Requirements

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0