Click or drag to resize

WeakActionHandlerT1 Class

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.
Inheritance Hierarchy
SystemObject
  AltaxoWeakActionHandlerT1

Namespace: Altaxo
Assembly: AltaxoCore (in AltaxoCore.dll) Version: 4.8.3179.0 (4.8.3179.0)
Syntax
C#
public class WeakActionHandler<T1>

Type Parameters

T1
Action parameter.

The WeakActionHandlerT1 type exposes the following members.

Constructors
 NameDescription
Public methodWeakActionHandlerT1(ActionT1, Object, String) Initializes a new instance of the WeakActionHandler class.
Public methodWeakActionHandlerT1(ActionT1, Type, String) Initializes a new instance of the WeakActionHandler class for a static event.
Top
Properties
 NameDescription
Public propertyEventSourceGets the event source. Attention! Use the returned value only locally, otherwise, you will get a dependence that you wanted to avoid.
Top
Methods
 NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodEventSink 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.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodRemoveRemoves the event handler from the event source, using the stored remove action..
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Operators
 NameDescription
Public operatorStatic member(WeakActionHandlerT1 to ActionT1) Converts this instance to an action that can be used to add or remove it from/to an event.
Top
Remarks
Typical use: (Attention: source has to be a local variable, not a member variable!)
C#
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:
C#
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:
C#
_weakActionHandler = new WeakActionHandler<MyArg>(this.EhActionHandling, x => source.ActionEvent -= x); // weakActionHandler is an instance variable of this class
source.ActionEvent += _weakActionHandler;
.
.
.
source.ActionEvent -= _weakActionHandler;
See Also