Is there a way to dynamically remove an event handler from an event without
knowing the name of the handler?
For example, how can ClassB remove the handler without knowing the name, or
how many handlers there are?
<code>
Public Class ClassA
Private m_ClassB As New ClassB
Public Sub Add()
m_ClassB.AddHandler(MyHandler)
' ...
m_ClassB.RemoveHandlers()
End Sub
Public Sub MyHandler()
' Handle event
End Sub
End Class
Public Class ClassB
Public Event DoStuff()
Public Sub AddHandler(handler As EventHandler)
AddHandler DoStuff, AddressOf handler
End Sub
Public Sub RemoveHandlers()
' *** Remove unknown handler(s) ***
RemoveHandler DoStuff, ???
End Sub
End Class
</code>
Presumably, the list of currently connected event handlers is held
somewhere. Can it be accessed in some way to remove an indeterminate number
of handlers?
TIA
Charles 4 8696
* "Charles Law" <bl***@nowhere.com> scripsit: Is there a way to dynamically remove an event handler from an event without knowing the name of the handler?
For example, how can ClassB remove the handler without knowing the name, or [...] Public Class ClassB
Public Event DoStuff()
Public Sub AddHandler(handler As EventHandler)
AddHandler DoStuff, AddressOf handler
End Sub
Public Sub RemoveHandlers()
' *** Remove unknown handler(s) *** RemoveHandler DoStuff, ???
End Sub
End Class </code>
Presumably, the list of currently connected event handlers is held somewhere. Can it be accessed in some way to remove an indeterminate number of handlers?
In 'ClassB', have a look at 'DoStuffEvent'. This is a hidden variable.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Thanks once again Herfried.
I was just never going to find that. Why is it hidden? I have looked it up
in the MSDN and the explanation is pure gobbledegook.
In my example, to remove all handlers of my event in all classes, would I
write
Delegate.RemoveAll(DoStuff, DoStuff) ?
I don't understand why there are two parameters.
Charles
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2i************@uni-berlin.de... * "Charles Law" <bl***@nowhere.com> scripsit: Is there a way to dynamically remove an event handler from an event
without knowing the name of the handler?
For example, how can ClassB remove the handler without knowing the name,
or [...] Public Class ClassB
Public Event DoStuff()
Public Sub AddHandler(handler As EventHandler)
AddHandler DoStuff, AddressOf handler
End Sub
Public Sub RemoveHandlers()
' *** Remove unknown handler(s) *** RemoveHandler DoStuff, ???
End Sub
End Class </code>
Presumably, the list of currently connected event handlers is held somewhere. Can it be accessed in some way to remove an indeterminate
number of handlers?
In 'ClassB', have a look at 'DoStuffEvent'. This is a hidden variable.
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
Herfried
On the same note, how about the reverse process? That is, given
Public Class ClassA
Public Event MyEvent()
....
AddHandler MyEvent, AddressOf ClassBInstance.MyEventHandler
....
End Class
When ClassBInstance is destroyed, how can all events that MyEventHandler
handles be disconnected without ClassB knowing what events have been linked?
Is there another hidden variable?
Charles
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2i************@uni-berlin.de... * "Charles Law" <bl***@nowhere.com> scripsit: Is there a way to dynamically remove an event handler from an event
without knowing the name of the handler?
For example, how can ClassB remove the handler without knowing the name,
or [...] Public Class ClassB
Public Event DoStuff()
Public Sub AddHandler(handler As EventHandler)
AddHandler DoStuff, AddressOf handler
End Sub
Public Sub RemoveHandlers()
' *** Remove unknown handler(s) *** RemoveHandler DoStuff, ???
End Sub
End Class </code>
Presumably, the list of currently connected event handlers is held somewhere. Can it be accessed in some way to remove an indeterminate
number of handlers?
In 'ClassB', have a look at 'DoStuffEvent'. This is a hidden variable.
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
* "Charles Law" <bl***@nowhere.com> scripsit: I was just never going to find that. Why is it hidden? I have looked it up in the MSDN and the explanation is pure gobbledegook.
That's VB.NET :-).
In my example, to remove all handlers of my event in all classes, would I write
Delegate.RemoveAll(DoStuff, DoStuff) ?
I don't understand why there are two parameters.
I currently cannot test it, but try '[Delegate].RemoveAll(FooEvent,
FooEvent)'. You can imagine 'FooEvent' as a "list" of delegates that
are invoked when you do a 'RaiseEvent'.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sujan |
last post by:
Hello all,
Is it possible to remove scrollbar(s) without using frames. Is there
any code which could be applied in body tag to remove scrollbar(s).
Thanks in adv,
Sujan
|
by: Rob Tiemens |
last post by:
hello,
I need to select the first and the second column of a table. But I
don't know the names of the columns.
Is there any way I can select only the first column from a table
without knowing...
|
by: gswork |
last post by:
Let's write a c program, without knowing what it does...
Some of you may recall Jim Roger's excellent series of posts (on
comp.programming) exploring the implementation of common software...
|
by: AdamM |
last post by:
Currently, my code reads from a database without knowing the order of the
columns like this:
string name = (string)datarow;
However, is there a way to write or do an INSERT back to a database...
|
by: CodeMotion |
last post by:
I have access to an internet directory and files will be placed in
this directory periodically. I am writing a service to poll that
directory and download the files for processing. I have figured...
| |
by: farseer |
last post by:
If i have an array of a certain type, is there away of initializing
with without knowing it's type? for example (forgive me if some of
this is syntactically incorrect)
if i have a procedure...
|
by: Familjen Karlsson |
last post by:
Here is an example from the help on the keword OleDbConnection, in VB.Net,
they don't give the path to the database just the word localhost. How can it
connect to the database without knowing where...
|
by: Andrzej Lipski |
last post by:
Hello I am developing a Windows Ce 5.0 mobile application. I followed the
example shown at :
Creating Self-Updating Applications With the .NET Compact Framework...
|
by: optimistx |
last post by:
I try to develope a bookmarklet, which hopefully can be activated on almost
any http-page (i.e. from any server).
The page can have unknown event handlers.
The bookmarklet wants to add its own...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |