Gemstone Common Library
Show/Hide TOC

# EventHandlerExtensionsSafeInvokeAsync TEventHandler, TEventArgs(TEventHandler, Object, ActionException, Delegate, Object, TEventArgs, Boolean) Method

Safely invokes event propagation asynchronously with custom event lock and exception handler that accepts user handler delegate, continuing even if an attached user handler throws an exception.

## Definition

Namespace: Gemstone.EventHandlerExtensions
Assembly: Gemstone.Common (in Gemstone.Common.dll) Version: 1.0.160 -- Release Build+19b74ac03cedad8575bb1ceb00051318b7421d0d
C#
View Source Request Example

    public static Task SafeInvokeAsync<TEventHandler, TEventArgs>(
    	this TEventHandler eventHandler,
    	Object? eventLock,
    	Action<Exception, Delegate>? exceptionHandler,
    	Object? sender,
    	TEventArgs args,
    	bool parallel = false
    )
    where TEventHandler : MulticastDelegate
    where TEventArgs : EventArgs

VB
View Source Request Example

    <ExtensionAttribute>
    Public Shared Function SafeInvokeAsync(Of TEventHandler As MulticastDelegate, TEventArgs As EventArgs) (
    	eventHandler As TEventHandler,
    	eventLock As Object,
    	exceptionHandler As Action(Of Exception, Delegate),
    	sender As Object,
    	args As TEventArgs,
    	Optional parallel As Boolean = false
    ) As Task

C++
View Source Request Example

    public:
    [ExtensionAttribute]
    generic<typename TEventHandler, typename TEventArgs>
    where TEventHandler : MulticastDelegate
    where TEventArgs : EventArgs
    static Task^ SafeInvokeAsync(
    	TEventHandler eventHandler,
    	Object^ eventLock,
    	Action<Exception^, Delegate^>^ exceptionHandler,
    	Object^ sender,
    	TEventArgs args,
    	bool parallel = false
    )

JavaScript
View Source Request Example

    JavaScript does not support generic types or methods.

#### Parameters

eventHandler TEventHandler
  Source EventHandler to safely invoke.
eventLock Object
  Locking object for accessing event handler invocation list; when set to null, lock will be on eventHandler.
exceptionHandler Action Exception, Delegate
  Custom delegate to handle encountered exceptions which includes parameter for event handler that threw the exception; when set to null, exception will be suppressed, see SuppressedException.
sender Object
  Event source.
args TEventArgs
  Event arguments.
parallel Boolean (Optional)
  Call event handlers in parallel, when attached handlers are greater than one.

#### Type Parameters

TEventHandler
  MulticastDelegate type commonly derived from EventHandler.
TEventArgs
  Type derived from EventArgs.

#### Return Value

Task

[Missing <returns> documentation for "M:Gemstone.EventHandlerExtensions.EventHandlerExtensions.SafeInvokeAsync``2(``0,System.Object,System.Action{System.Exception,System.Delegate},System.Object,``1,System.Boolean)"]

#### Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type TEventHandler. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

## See Also

#### Reference

EventHandlerExtensions Class
SafeInvokeAsync Overload
Gemstone.EventHandlerExtensions Namespace