Re: CLR event model

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: garbage collector (_at_discussions.microsoft.com)
Date: 09/21/04


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]
>



Relevant Pages

  • Re: CLR event model
    ... and not a reference to the Program object. ... > object that implements the eventhandler. ... I wanted the grid to be notified of any ... all business objects now held a reference to the collection ...
    (microsoft.public.dotnet.framework.clr)
  • Re: CLR event model
    ... You might want to check out Ian Griffiths' Weak Reference events handlers ... object that implements the eventhandler. ... I wanted the grid to be notified of any ... all business objects now held a reference to the collection ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Gruul - first experience :)
    ... My preffered addon for this is Grid: ... You can now see one square for each person in your party/raid, ... To target them just click on their square. ...
    (alt.games.warcraft)
  • Re: WoW IU vs. Addon UIs
    ... I want to click on somebody on Grid to target them, ... With clique you shouldn't be clicking on someone's portrait in ... button to cast a spell on them. ...
    (alt.games.warcraft)
  • Re: Garmin Geko - Accuracy of conversion to Bristish National Grid
    ... Looking at the above reference it would appear that I also need to be ... > able to set the latitude of the origin to 49 Deg North. ... > resulting grid reference is useless. ... user AFTER you have set the display format. ...
    (sci.geo.satellite-nav)