WeakActionHandler<'T1> Type

Mediates an action event with one argument, holding only a weak reference to the event sink. Thus there is no reference created from the event source to the event sink, and the event sink can be garbage collected.

Typical use: (Attention: source has to be a local variable, not a member variable!)

            source.ActionEvent += new WeakActionHandler<MyArg>(this.EhActionHandling, x => source.ActionEvent -= x);
Sometimes it might be neccessary to use explicitly the event handler method of this instance:
            source.ActionEvent += new WeakActionHandler<MyArg>(this.EhActionHandling, x=> source.ActionEvent -= x.EventSink).EventSink;
You can even maintain a reference to the WeakActionHandler instance in your event sink instance, in case you have to remove the event handling programmatically:
            _weakActionHandler = new WeakActionHandler<MyArg>(this.EhActionHandling, x => source.ActionEvent -= x); // weakActionHandler is an instance variable of this class
            source.ActionEvent += _weakActionHandler;
            .
            .
            .
            source.ActionEvent -= _weakActionHandler;

Constructors

Constructor Description

WeakActionHandler(handler, eventSource, eventName)

Full Usage: WeakActionHandler(handler, eventSource, eventName)

Parameters:
    handler : Action<'T1> - The event handler method (the event sink).
    eventSource : obj - The object that holds the event source.
    eventName : string - The name of the event.

Initializes a new instance of the WeakActionHandler class.

Typcical usage:

source.Changed += new WeakActionHandler<MyClass>(this.EhHandleChange, source, nameof(source.Changed));

handler : Action<'T1>

The event handler method (the event sink).

eventSource : obj

The object that holds the event source.

eventName : string

The name of the event.

WeakActionHandler(handler, eventSourceType, eventName)

Full Usage: WeakActionHandler(handler, eventSourceType, eventName)

Parameters:
    handler : Action<'T1> - The event handler method (the event sink).
    eventSourceType : Type - The type of object that holds the static event.
    eventName : string - The name of the static event.

Initializes a new instance of the WeakActionHandler class for a static event.

Typical usage:

StaticClass.Changed += new WeakActionHandler(this.EhHandleChange, typeof(StaticClass), nameof(StaticClass.Changed));

handler : Action<'T1>

The event handler method (the event sink).

eventSourceType : Type

The type of object that holds the static event.

eventName : string

The name of the static event.

Instance members

Instance member Description

this.EventSink

Full Usage: this.EventSink

Parameters:
    t1 : 'T1 - First action argument.

Handles the event from the original source. You must not call this method directly. However, it can be neccessary to use the method reference if the implicit casting fails. See remarks in the description of this class.

t1 : 'T1

First action argument.

this.EventSource

Full Usage: this.EventSource

Returns: obj

Gets the event source. Attention! Use the returned value only locally, otherwise, you will get a dependence that you wanted to avoid.

Returns: obj

this.Remove

Full Usage: this.Remove

Removes the event handler from the event source, using the stored remove action..

Static members

Static member Description

op_ImplicitweakHandler

Full Usage: op_ImplicitweakHandler

Parameters:
Returns: Action<'T1>

weakHandler : WeakActionHandler<'T1>
Returns: Action<'T1>