EventInfo.RemoveEventHandler(Object, Delegate) Method

Definition

Removes an event handler from an event source.

C#
public virtual void RemoveEventHandler(object target, Delegate handler);
C#
public virtual void RemoveEventHandler(object? target, Delegate? handler);
C#
public void RemoveEventHandler(object target, Delegate handler);

Parameters

target
Object

The event source.

handler
Delegate

The delegate to be disassociated from the events raised by target.

Implements

Exceptions

The event does not have a public remove accessor.

The handler that was passed in cannot be used.

The target parameter is null and the event is not static.

-or-

The EventInfo is not declared on the target.

Note: In .NET for Windows Store apps or the Portable Class Library, catch Exception instead.

The caller does not have access permission to the member.

Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, MemberAccessException, instead.

Remarks

This method attempts to remove the delegate that may synchronize this event on the target object.

When an event is raised by target, the method or methods encapsulated by handler will no longer be invoked.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

See also