ComAwareEventInfo.RemoveEventHandler(Object, Delegate) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Detaches an event handler from a COM object.
public:
override void RemoveEventHandler(System::Object ^ target, Delegate ^ handler);
public override void RemoveEventHandler (object target, Delegate handler);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public override void RemoveEventHandler (object target, Delegate handler);
override this.RemoveEventHandler : obj * Delegate -> unit
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
override this.RemoveEventHandler : obj * Delegate -> unit
Public Overrides Sub RemoveEventHandler (target As Object, handler As Delegate)
Parameters
- target
- Object
The target object that the event delegate is bound to.
- handler
- Delegate
The event delegate.
- Attributes
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 is similar to the EventInfo.RemoveEventHandler(Object, Delegate) method, except that it allows you to detach events from COM objects.
If target
is a COM object, this method releases a delegate to an event by using the ComEventsHelper.Remove(Object, Guid, Int32, Delegate) method.
RemoveEventHandler facilitates unregistering COM event sinks that forward calls to corresponding managed delegates. It requires the following information:
The target object itself (
target
).The GUID of the source interface.
The DispID of the method on the COM interface that corresponds to the specified event.
The delegate that would be invoked when the COM object triggers the corresponding event (
handler
).
RemoveEventHandler looks up the corresponding COM source interface (specified as the first parameter of the ComEventInterfaceAttribute.ComEventInterfaceAttribute(Type, Type) constructor). It then it looks up a method on the source interface whose name is identical to the event name. The value of GuidAttribute
on the source interface is the GUID that is passed to ComEventsHelper.Remove(Object, Guid, Int32, Delegate); the value of DispIDAttribute
on the method is the DispID value that is passed to ComEventsHelper.Remove(Object, Guid, Int32, Delegate).