RoutedEventArgs.InvokeEventHandler Method

When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation.

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

protected virtual void InvokeEventHandler(
	Delegate genericHandler,
	Object genericTarget
)

Parameters

genericHandler
Type: System.Delegate

The generic handler / delegate implementation to be invoked.

genericTarget
Type: System.Object

The target on which the provided handler should be invoked.

The base implementation incorporates reflection to determine the right handler for any case where the handler is not literally RoutedEventHandler, and this reflection step does have some performance consequences. Invocations can be made more efficient by not relying on reflection. This is the scenario that motivates this method being available for any routed event arguments class that choose to override it. Implementations should not call the base for this method, because your implementation should already be responsible for invoking the type safe handlers.

Notes to Inheritors

This method is intended to be overridden by derived event data classes to provide more efficient invocation of their delegates. The implementation should cast the provided genericHandler to the type-specific delegate, and then invoke that handler.

The default implementation will attempt to invoke the provided handler, attempting to cast it as RoutedEventHandler. If either genericHandler or genericTarget is provided as null, exceptions will be raised.

The following is pseudocode that illustrates a basic pattern that can be used for implementation. Here, MyRoutedEventHandler is a subclass of RoutedEventHandler.

public class MyRoutedEventArgs : RoutedEventArgs 
{
// other members omitted 
    protected override void InvokeEventHandler(Delegate genericHandler, object genericTarget) {
        MyRoutedEventHandler handler = (MyRoutedEventHandler) genericHandler;
        handler(genericTarget, this);
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft