πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #47

Re: Custom Delegation

#47
From: Andre
Date: Mon, 29 May 2006 09:42
62 lines
3050 bytes
thanks for clearing that out for me.

"Joanna Carter [TeamB]" <joanna@not.for.spam> wrote in message 
news:447abdd8$1@newsgroups.borland.com...
> "Andre" <andretruter@webmail.co.za> a οΏ½crit dans le message de news:
> 447aa0bd@newsgroups.borland.com...
>
> |I have a series of my own eventHandler delegates, and a few events using
> | these delegates. All works fine. Im just concerned about one thing.
> | In some litrature the author define a event like this:
> |
> | public event eventHandler onEvent
> | {
> |    add{/// some code}
> |    remove{/// some code}
> | }
> |
> | assuming which are used when doing:
> |
> | myObj.onEvent += new eventHandler(this.onEventAction);
> |
> | and
> |
> | myObj.onEvent -= new eventHandler(this.onEventAction);
> |
> | Now, is this a cleanup routine when using -= or does it just add
> additional
> | functionality to the event contruction/destruction?
>
> Using -= removes a handler from an event, nothing more.
>
> | Is this type of coding neccesary? good practice or mandatory for event
> | cleanup?
>
> This style of coding where you have to call "+/-= new EventHandler(...)"
> become optional in C# 2.0 where you can simplify the statement to 
> something
> like :
>
> myObj.Event += HandleEventAction;
> myObj.Event -= HandleEventAction;
>
> | As far as I know, the object owning the event gets disposed by GC
> | automaticlly.
> | Should I call the -= manouver when the object gets disposed?
>
> No, you don't need to do anything as you don't know when the objects will
> actually get collected. The only possible gotcha is if you create 
> temporary
> objects with handler methods; if you were to expect the temporary objects 
> to
> be GCed, you would have to ensure that their handler methods were
> disconnected, otherwise the list of delegates would grow indefinitely
> everytime a new temporary object's handler was connected.
>
> Joanna
>
> -- 
> Joanna Carter [TeamB]
> Consultant Software Engineer
>
> 
Technical Details
Message-ID: <447ac1f2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeed.inode.at!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail
References: <447aa0bd@newsgroups.borland.com> <447abdd8$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,bb4758d9cad65d98
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII
From: "Andre" <andretruter@webmail.co.za>
Newsgroups: borland.public.csharpbuilder.language.csharp
References: <447aa0bd@newsgroups.borland.com> <447abdd8$1@newsgroups.borland.com>
Subject: Re: Custom Delegation
Date: Mon, 29 May 2006 11:42:07 +0200
Lines: 64
Organization: Bluewater Systems
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
X-RFC2646: Format=Flowed; Original
X-Antivirus: avast! (VPS 0621-4, 05/26/2006), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 196.207.45.253
Message-ID: <447ac1f2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1148895730 196.207.45.253 (29 May 2006 02:42:10 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeed.inode.at!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail