ComAwareEventInfo.RemoveEventHandler(Object, Delegate) 方法

定义

将事件处理程序从 COM 对象分离。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)

参数

target
Object

事件委托所绑定的目标对象。The target object that the event delegate is bound to.

handler
Delegate

事件委托。The event delegate.

属性

例外

该事件没有公共 remove 访问器。The event does not have a public remove accessor.

无法使用传入的处理程序。The handler that was passed in cannot be used.

target 参数为 null,并且此事件不是静态事件。The target parameter is null and the event is not static.

-or- 未在目标上声明 EventInfoThe EventInfo is not declared on the target.

调用方没有对成员的访问权限。The caller does not have access permission to the member.

注解

此方法与 EventInfo.RemoveEventHandler(Object, Delegate) 方法类似,只是它允许你将事件与 COM 对象分离。This method is similar to the EventInfo.RemoveEventHandler(Object, Delegate) method, except that it allows you to detach events from COM objects.

如果 target 是 COM 对象,则此方法通过使用方法向事件发布委托 ComEventsHelper.Remove(Object, Guid, Int32, Delegate)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 简化将调用转发到相应托管委托的 COM 事件接收器。RemoveEventHandler facilitates unregistering COM event sinks that forward calls to corresponding managed delegates. 它需要以下信息:It requires the following information:

  • 目标对象本身 (target) 。The target object itself (target).

  • 源接口的 GUID。The GUID of the source interface.

  • 与指定事件相对应的 COM 接口上的方法的 DispID。The DispID of the method on the COM interface that corresponds to the specified event.

  • 当 COM 对象触发相应事件时将调用的委托 (handler) 。The delegate that would be invoked when the COM object triggers the corresponding event (handler).

RemoveEventHandler 查找 (指定为构造函数) 的第一个参数的对应 COM 源接口 ComEventInterfaceAttribute.ComEventInterfaceAttribute(Type, Type)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. GuidAttribute源接口上的值是传递给的 GUID ComEventsHelper.Remove(Object, Guid, Int32, Delegate) ; DispIDAttribute 方法上的值是传递给的 DispID 值 ComEventsHelper.Remove(Object, Guid, Int32, Delegate)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).

适用于