Re: CLR event model
From: garbage collector (_at_discussions.microsoft.com)
Date: 09/21/04
- Next message: Jonathan Keljo [MS]: "RE: Passing constants to functions + boxing"
- Previous message: Richard Blewett [DevelopMentor]: "Re: CLR event model"
- In reply to: Richard Blewett [DevelopMentor]: "Re: CLR event model"
- Next in thread: Per Millard: "Re: CLR event model"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 21 Sep 2004 13:37:07 -0700
Hi Richard
Thanx very much for the info. I fact, I already came up with that idea and
it worked
fine but I was afraid that the Target property of the WeakReference object
would
not be set to null when the Target object was garbage collected thus leaving
an
invalid reference after the next heap re-organization by the GC.
However, in some of the comments for the article, its stated that the target
object
reference is in fact reset upon garbage collection thus making this approach
an
accepable solution.
Thanx again
Regards
Per Millard
.NET Architect
"Richard Blewett [DevelopMentor]" wrote:
> You might want to check out Ian Griffiths' Weak Reference events handlers
>
> http://www.interact-sw.co.uk/iangblog/2004/06/06/weakeventhandler
>
> Regards
>
> Richard Blewett - DevelopMentor
>
> http://staff.develop.com/richardb/weblog
>
> nntp://news.microsoft.com/microsoft.public.dotnet.framework.clr/<023CBCE6-F58E-4584-8E30-36FB35D9BFFC@microsoft.com>
>
> Does anybody have to address the same issues as me regarding the event model
> in the CLR. ?
>
> Events in the CLR are obviously tightly coupled, meaning the if an object
> adds itself to an event of another object, that objects will hold a
> reference to the
> object that implements the eventhandler. What this actually means is, that
> implementing an eventhandler for a longlife object will force you remove the
> event handler from the object, if you want the object containing the
> eventhandler to go away before the longlife object does.
>
> One of the problems for me was implementing a grid control that shows a
> collection of businessobjects. I wanted the grid to be notified of any
> changes made to the collection and its objects, so I added an event on the
> business objects and some events on the object collection. When an object was
> added to the collection, the collection added an eventhandler to the object,
> listning for any changes made to it. When passing the objectcollection to the
> grid, the grid attached itself to the events of the collection thus allowing
> the grid to update when changes where made. This all worked fine, but here
> comes the tricky bit. I wanted to be able to reuse my collection of business
> objects. Hovever, all business objects now held a reference to the collection
> and the collection held a reference to the grid control. I had no choice but
> to unattach all the eventhandlers or have the grid control create its own
> instance of the object collection and then assigning the objects from the
> original collection to it.
>
> I have solved this problem by using windows messaging, but I can't understand
> why the CLR event model was not implemented as loosely coupled model.
>
> Regards
>
> Per M.
> .NET Architect
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
>
>
>
> [microsoft.public.dotnet.framework.clr]
>
- Next message: Jonathan Keljo [MS]: "RE: Passing constants to functions + boxing"
- Previous message: Richard Blewett [DevelopMentor]: "Re: CLR event model"
- In reply to: Richard Blewett [DevelopMentor]: "Re: CLR event model"
- Next in thread: Per Millard: "Re: CLR event model"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|