In .net 4.0, there is a type of ConditionalWeakTable , which can be used, although somewhat inconveniently, to request notification when an arbitrary object becomes suitable for completion. If a ConditionalWeakTable contains a record matching one object (say, the 451st object) with another object (for example, the created 730th object), then as long as the record remains in the table, and root links exist for both the table and and for object # 451, the table will be considered the root link to object # 730. If there is no anchor link for object # 451, the table will cease to be the root link to object # 730.
Therefore, if object # 730 contains a link to a table and object # 730 exists outside the table, object # 730 will have the right to finalize simultaneously with object # 451. If object # 730 overrides Finalize() , this override can be used as a notification that the object # 451 received the right to complete.
Note that the finalizer for object # 730 will fire only once, even if object # 451 resurrects itself and re-registers to complete. One could write code that will trigger a notification when object # 451 is indeed dead and buried, even if it is resurrected several times first, but there is no particularly clean way to do this.
supercat
source share