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;
Constructor | Description |
Full Usage:
WeakActionHandler(handler, eventSource, eventName)
Parameters:
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.
|
Typcical usage: source.Changed += new WeakActionHandler<MyClass>(this.EhHandleChange, source, nameof(source.Changed));
|
|
Typical usage: StaticClass.Changed += new WeakActionHandler(this.EhHandleChange, typeof(StaticClass), nameof(StaticClass.Changed)); |
Instance member | Description |
Full Usage:
this.EventSink
Parameters:
'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.
|
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.
|
Full Usage:
this.Remove
|
Removes the event handler from the event source, using the stored remove action.. |
Static member | Description |
Full Usage:
op_ImplicitweakHandler
Parameters:
WeakActionHandler<'T1>
Returns: Action<'T1>
|
|