Hi all,
We have developed some forms that dynamically build the
controls and then need to add event handlers to them.
Does anyone know the cumulative effect of adding handlers
and not removing them? I have done Removehandler calls
when the handler doesn't exist so I assume that the
handlers are not maintained as a collection.

Jim

Re: Addhandler/Removehandler by TJoker

TJoker
Tue Sep 09 15:34:39 CDT 2003

You'll get duplicate calls to your handlers.

TJ

"Jim" <jimstallings@msn.com> wrote in message
news:59b401c37710$51632520$a501280a@phx.gbl...
> Hi all,
> We have developed some forms that dynamically build the
> controls and then need to add event handlers to them.
> Does anyone know the cumulative effect of adding handlers
> and not removing them? I have done Removehandler calls
> when the handler doesn't exist so I assume that the
> handlers are not maintained as a collection.
>
> Jim



Re: Addhandler/Removehandler by Herfried

Herfried
Tue Sep 09 16:23:27 CDT 2003

Hello,

"Jim" <jimstallings@msn.com> schrieb:
> We have developed some forms that dynamically build the
> controls and then need to add event handlers to them.
> Does anyone know the cumulative effect of adding handlers
> and not removing them? I have done Removehandler calls
> when the handler doesn't exist so I assume that the
> handlers are not maintained as a collection.

Handlers may fire twice. I suggest you read the chapter about events in
the documentation:

Events and Delegates (Visual Basic Language Concepts)
http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconeventsdelegatesinheritance.asp

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet



Re: Addhandler/Removehandler by Jim

Jim
Tue Sep 09 16:47:50 CDT 2003

Hi guys,
Thanks for the replies. Yes that was my question really,=20
whether anyone knew for sure that the handlers would in=20
fact be duplicated or whether the event queue would=20
detect that a hander was already registered for contol X=20
and method Y. The documentation is not detailed enough=20
to make that determination so I guess I just have to play=20
with the code to see for sure.

jim




>-----Original Message-----
>Hello,
>
>"Jim" <jimstallings@msn.com> schrieb:
>> We have developed some forms that dynamically build the
>> controls and then need to add event handlers to them.
>> Does anyone know the cumulative effect of adding=20
handlers
>> and not removing them? I have done Removehandler calls
>> when the handler doesn't exist so I assume that the
>> handlers are not maintained as a collection.
>
>Handlers may fire twice. I suggest you read the chapter=20
about events in
>the documentation:
>
>Events and Delegates (Visual Basic Language Concepts)
>http://msdn.microsoft.com/library/en-
us/vbcn7/html/vaconeventsdelegatesinheritance.asp
>
>--=20
>Herfried K. Wagner
>MVP =B7 VB Classic, VB.NET
>http://www.mvps.org/dotnet
>
>
>.
>

Re: Addhandler/Removehandler by v-yiy

v-yiy
Wed Sep 10 00:37:10 CDT 2003

Hi Jim,
Just as our MVP and other community users said, you will fire the
event twice.
The event in .NET Framework is implemented by the MultiDelegate class,
which uses an linked list to save event handlers.It is not like an
Collection and won't check for duplicate handlers. for more information
,please refer to
ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemmulticastdelegatecla
sstopic.htm
If you have any further questions , please be free to let me know!
Thanks!

Kind regards,

Ying-Shen Yu [MS]
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "Jim" <jimstallings@msn.com>
| Sender: "Jim" <jimstallings@msn.com>
| References: <59b401c37710$51632520$a501280a@phx.gbl>
<eU$8dixdDHA.3596@tk2msftngp13.phx.gbl>
| Subject: Re: Addhandler/Removehandler
| Date: Tue, 9 Sep 2003 14:47:50 -0700
| Lines: 42
| Message-ID: <04c301c3771c$04235580$a401280a@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: quoted-printable
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN3HAQj7olZy3vnQp2jDEudbVgEPg==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51984
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hi guys,
| Thanks for the replies. Yes that was my question really,
| whether anyone knew for sure that the handlers would in
| fact be duplicated or whether the event queue would
| detect that a hander was already registered for contol X
| and method Y. The documentation is not detailed enough
| to make that determination so I guess I just have to play
| with the code to see for sure.
| jim
| >-----Original Message-----
| >Hello,
| >
| >"Jim" <jimstallings@msn.com> schrieb:
| >> We have developed some forms that dynamically build the
| >> controls and then need to add event handlers to them.
| >> Does anyone know the cumulative effect of adding
| handlers
| >> and not removing them? I have done Removehandler calls
| >> when the handler doesn't exist so I assume that the
| >> handlers are not maintained as a collection.
| >
| >Handlers may fire twice. I suggest you read the chapter
| about events in
| >the documentation:
| >
| >Events and Delegates (Visual Basic Language Concepts)
| >http://msdn.microsoft.com/library/en-
| us/vbcn7/html/vaconeventsdelegatesinheritance.asp
| >
| >--
| >Herfried K. Wagner
| >MVP · VB Classic, VB.NET
| >http://www.mvps.org/dotnet
| >
| >
| >.
| >
|


Re: Addhandler/Removehandler by Stuart

Stuart
Wed Sep 10 03:00:55 CDT 2003

Also is you do not unregister the events - even though the
registered component may not be used anymore the event
register will still exist, preventing the component from
being collected and worse it still responds to events!

Stuart

>-----Original Message-----
>You'll get duplicate calls to your handlers.
>
>TJ
>
>"Jim" <jimstallings@msn.com> wrote in message
>news:59b401c37710$51632520$a501280a@phx.gbl...
>> Hi all,
>> We have developed some forms that dynamically build the
>> controls and then need to add event handlers to them.
>> Does anyone know the cumulative effect of adding
handlers
>> and not removing them? I have done Removehandler calls
>> when the handler doesn't exist so I assume that the
>> handlers are not maintained as a collection.
>>
>> Jim
>
>
>.
>