Sdílet prostřednictvím


EventInfo.RemoveEventHandler Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Removes an event handler from an event source.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<DebuggerHiddenAttribute> _
<DebuggerStepThroughAttribute> _
Public Overridable Sub RemoveEventHandler ( _
    target As Object, _
    handler As Delegate _
)
[DebuggerHiddenAttribute]
[DebuggerStepThroughAttribute]
public virtual void RemoveEventHandler(
    Object target,
    Delegate handler
)

Parameters

  • handler
    Type: System.Delegate
    The delegate to be unhooked from the event source.

Exceptions

Exception Condition
InvalidOperationException

The event does not have a public remove accessor.

ArgumentException

The handler that was passed in cannot be used.

TargetException

The target parameter is nulla null reference (Nothing in Visual Basic) and the event is not static.

-or-

The EventInfo is not declared on the target.

MemberAccessException

This member is invoked late-bound through mechanisms such as Type.InvokeMember.

Remarks

Use the AddEventHandler method to hook up events in late-bound scenarios.

This method attempts to unhook an event handler for the current event on the event source specified by target, by calling the remove accessor.

NoteNote:

In reflection, the remove accessor can be obtained by calling the GetRemoveMethod method.

For an example, see the AddEventHandler method.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.